This article has been synced to your personal blog: liyuyu.cn
The recent use of international multilingual (English + Chinese) in the project has found a problem when used. When the screen rotates. The app Language (Chinese) actively converts itself to the system language (English). The android:configchanges= "orientation|screensize" property with activity set is also invalid. So help StackOverflow, you know, the last problem to conquer. The article was then collated for reference.
1. New Functionapplication class inherits application. Overwrite the onconfigurationchanged. The code is as follows:
public class Functionapplication extends application{ @Override public void Onconfigurationchanged ( Configuration newconfig) { //TODO auto-generated method Stub super.onconfigurationchanged (Newconfig); Tochinese (); } public void Tochinese () { 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);} }
2. Change the Androidmanifest.xml file. The application node is specified for our own definedfunctionapplication
<application android:name= "com.xxx.xxxx.FunctionApplication" android:allowbackup= "true" Android : configchanges= "Orientation|screensize|locale" android:icon= "@drawable/icon" android:label= "@string/ App_name " android:theme=" @style/apptheme ">
So far. The problem of language failure after rotating the screen can be overcome.
Access to the relevant information. When the onconfigurationchanged (Configuration Newconfig) method is triggered when the screen rotates. This newconfig is the system, which is why the language will switch to the system language. So here we can set the locale again.
The solution to the international language invalidation after Android spins the screen