This article has been synced to your personal blog: liyuyu.cn
Recently in the project to use the internationalization of multi-language (English + Chinese), but in the use of a problem, when the screen rotated, the app language (Chinese) automatically converted to the system language (English), set the activity of the android:configchanges= " Orientation|screensize "Property is also invalid, so help StackOverflow, you understand, the last problem solved, so organized this article for reference.
1. New Functionapplication class inherits application, overwrite onconfigurationchanged, 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. Modify the Androidmanifest.xml file, the application node is assigned to our customfunctionapplication
<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 ">
at this point, the problem of language failure after rotating the screen can be solved. Looking at the relevant data, found that when the screen rotation triggered the onconfigurationchanged (Configuration newconfig) method, the Newconfig is the system, which is why the language will switch to the system language reasons, So here we can set the locale again.
Solutions for international language invalidation after Android spins the screen