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