Android switching system language, Automatic Update app interface display language

Source: Internet
Author: User

The function that needs to be done is to modify the system language after clicking on the specified button and let the app follow the system switch language

private void Switchlanguage () {Iactivitymanager am = Activitymanagernative.getdefault (); Configuration config = null; try {config = am.getconfiguration ();//Change System language if (Config.locale.equals (locale.simplified_ Chinese)) {Config.locale = Locale.english;} else {config.locale = Locale.simplified_chinese;} Update system Setup am.updateconfiguration (config);//backupmanager.datachanged ("com.android.providers.settings");} catch (RemoteException e) {e.printstacktrace ();} System.out.println (Config.locale);//updateui ();}

Add permissions

<uses-permission android:name= "Android.permission.CHANGE_CONFIGURATION"/>

The above method has been completed to modify the system's language, open the system settings interface

ADB shell am start-n com.android.settings/. Settings

You can find that the language of the Setup interface has been changed by the system and some steps are required if you want to change the language display for the current app

In the properties of the activity, add

android:configchanges= "Locale"

The practice of many articles on the internet ends, the author to this step does not automatically update the interface language, because the interface is not updated

Add an update interface to the app, update the interface after changing the system language, and initially test discovery to switch the interface language. Further testing found that the language of the application interface is the opposite of the current language of the system, that is, a slow shot, as I said above, when the system language is Chinese, my app is displayed in English, and my app displays Chinese when the system language is English.

When you change the system language to system settings, it is found that the interface will not be updated after you have selected a language of about 2s


Guess you should use the radio to find out about the information

So I registered the broadcast

<receiver android:name= " Com.coship.entropic.factorytest.receiver.MyBroadcastReceiver ">     < Intent-filter>          <action android:name= " Android.intent.action.LOCALE_CHANGED " />     </intent-filter></ Receiver> 
public static mainactivity activity = null;//is applied over the Mainactivity initialization pass @Override public void OnReceive (context context,        Intent Intent) {if (Intent.getaction (). Equals (intent.action_locale_changed)) {Activity.initview (); }     }

Interface update processing is relatively rough, but also hope the great God advice!

Android switching system language, Automatic Update app interface display language

Related Article

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.