I applied the language switch when I clicked a button in the application. It is not directly in Android, but it can be done. There are two main problems: 1) The change in the language standard does not change. System Configuration - The locale of the system. Changing the language to French, for example, in your application, does not change the fact that your device is configured, for example, in English. Therefore, at any change in the configuration of your application - orientation, hiding the keyboard, etc., the application locale returns to the system language. 2) Another problem is that changing the language standard in your application does not update the user interface, it does not redraw the views. This makes it difficult to jump at runtime. Updating / reloading must be done manually, that is, there must be a method that updates each view with localized text / message / value.
So, first you need to define localized resources: value, value-en, value-fr, etc. Then it will be a code which, for example, will be made by pressing the power button.
private Locale myLocale; private void onFR_langClicked(View v){ myLocale = new Locale("fr");
It would be nice to separate the two steps in two ways: one to switch the language that causes the user interface to be updated.
Then you also need to process the configuration change and make sure that the language remains what you intended. Google recommends that you do not change the configuration configuration. The manifest should contain this for each activity:
<activity android:name=". ..." android:configChanges="locale|orientation|keyboardHidden" >
which allows you to define your own change handler:
@Override public void onConfigurationChanged(Configuration newConfig){ super.onConfigurationChanged(newConfig); if (myLocale != null){ newConfig.locale = myLocale; Locale.setDefault(myLocale); getBaseContext().getResources().updateConfiguration(newConfig, getBaseContext().getResources().getDisplayMetrics()); } }
Hope this helps. Hope you understand the principle.