2

I am developing an android app and the task is to support three languages. In the first screen the user selects language and rest of the app should appear in selected language.

I can use localization feature such as creating a default res/values/string.xml and language specific files res/values-fr/strings.xml. When the app is opened on a device with FR locale all strings appear translated.

Question: How do I force a locale on button click so that the next activity should use res/values-fr/strings.xml

ankitjaininfo
  • 11,961
  • 7
  • 52
  • 75

1 Answers1

1

Give it a try:

public class SigmaMiddleEastApplication extends PPGApplication {

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        newConfig.locale = Locale.ENGLISH;
        super.onConfigurationChanged(newConfig);

        Locale.setDefault(newConfig.locale);
        getBaseContext().getResources().updateConfiguration(newConfig, getResources().getDisplayMetrics());
    }
}

or take a look at the following attribute:

android:configChanges="locale"
enigma
  • 131
  • 3