Ahmed Abidi Ahmed Abidi - 6 months ago 31
Android Question

Change app language in android 5.0 doesn't work

I'm using this code below to change my app language on button click (changing from french to english for example), it's works fine on android 4.0 + but on 5.0 it doesn't.

Locale localeEn = new Locale("en_US");
Locale.setDefault(localeEn);
Configuration configEn = new Configuration();
configEn.locale = localeEn;
getApplicationContext().getResources().updateConfiguration(configEn, null);
this.recreate();


Any clues why please?

edit :
this is my manifest ( with android:configChanges )

<activity
android:name=".activities.LoginActivity"
android:configChanges="orientation|locale"
android:label="@string/app_name"
android:screenOrientation="portrait"/>

Answer

Try to change from this:

Locale localeEn = new Locale("en_US");
Locale.setDefault(localeEn);

to this

String language = "en";
String country = "US";
Locale locale = new Locale(language , country);