There are several ways to implement multi-language switching for Android applications, and there are a lot of information on the web, and there is a simple and effective way.
The steps are as follows:
Create a new folder in the resource file Values-en, Create a new Strings.xml, copy the contents of the Strings.xml in the default values folder to Strings.xml in Values-en, and then convert the Chinese content in the folder to English, for example <string name = "Set" > Set </string> Convert to <string name= "set" >set</string>
Then add a method to the main activity
The code is as follows:
public void Switchlanguage (locale locale) {
Configuration config = Getresources (). GetConfiguration ();//Get Set Object
Resource resources = Getresources ();//Get Res Object
Displaymetrics DM = Resources.getdisplaymetrics ();//Get screen parameters: mainly resolution, pixels, etc.
Config.locale = locale; Chinese Simplified
Resources.updateconfiguration (config, DM);
}
It is then called in the OnCreate function (and must also be called in the oncreate function ).
For example:
Switchlanguage (Locale.getdefault ()); or Switchlanguage (locale.us);
Finally, it is important to note that there are two places to configure in the Androidmanifest.xml file:
1. Add this attribute to the corresponding activity node: android:configchanges= "Locale"
2. Add Permission: <uses-permission android:name= "Android.permission.CHANGE_CONFIGURATION"/>
Multi-language switching for Android apps