As the title stated, you can force your application to be localize on an application basis and not system basis. In this article we would use german and english. To do this you have to edit something on your oncreate function on your default activity.
import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
public class Main extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Locale locale = new Locale(Locale.GERMAN);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());
this.setContentView(R.layout.main);
}
}
Info for Android 2.0:
Add android:configChanges=”locale” to your activity nodes on the manifest file.
<activity android:name=”.Main” android:configChanges=”locale” android:label=”@string/app_name” />
Info for Motorola Milestone/Droid and compile with Android 1.5/1.6:
Add support-screens to your manifest file, else the scaling of the milestone/droid is wrong.
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:anyDensity="true"
/>
Code Explanation:
Locale locale = new Locale(Locale.GERMAN);
Here we create a new Locale for GERMAN.
Configuration config = new Configuration();
config.locale = locale;
This creates a new Configuration and then we change the locale of this configuration with our geman locale.
getBaseContext().getResources().updateConfiguration(config,
Here we update the configuration of our basecontext’s resources.
getBaseContext().getResources().getDisplayMetrics());
转自:http://android.chrisonline.at/?p=259