The Android Application is still well internationalized. By setting the name of the resource file, for example, values-ZH-RCN, the system will automatically set it based on the language set by the current system, by default, resource files under the values directory are selected. If an application needs to specify the default language, no matter what language the system sets, the default language will be displayed. How can this problem be solved? In fact, it is very simple. It only takes three steps.
Step 1: Write a class (functionapplication) to inherit the application and implement the following methods in the oncreate () method:
?
1234567891011 |
@Override public void onCreate() { super .onCreate(); String languageToLoad =
"zh" ; Locale locale =
new Locale(languageToLoad); Locale.setDefault(locale); Configuration config = getResources().getConfiguration(); DisplayMetrics metrics = getResources().getDisplayMetrics(); config.locale = Locale.SIMPLIFIED_CHINESE; getResources().updateConfiguration(config, metrics); } |
Step 2: Set the default androidmanifest. xmlapplication to the following:
?
12345 |
< application android:name = ".FunctionApplication" android:icon = "@drawable/ic_launcher" android:label = "@string/app_name" android:configChanges = "locale"
> |
Android: configchanges = "locale" is the key. Of course, if you do not allow the entire application to be programmed with Chinese characters, you do not need to inherit the application, simply add the first method in the class that inherits the activity. Of course, do not forget to add Android: configchanges = "locale" to the activity tag ".
Step 3: add the corresponding permissions:
?
1 |
< uses-permission
android:name = "android.permission.CHANGE_CONFIGURATION" /> |