The solution to the international language invalidation after Android spins the screen

Source: Internet
Author: User

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

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.