Solutions for international language invalidation after Android spins the screen

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.