Skip to content Skip to sidebar Skip to footer

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 l

Solution 1:

Try to change from this:

LocalelocaleEn=newLocale("en_US");
Locale.setDefault(localeEn);

to this

Stringlanguage="en";
Stringcountry="US";
Localelocale=newLocale(language , country);

Solution 2:

My solution, that i got from Udhay, works when user changes the language in actionbar and app "refreshes" with selected language. I am using android 6.0.

There is no need to add locale to androidManifest.

@OverridepublicbooleanonOptionsItemSelected(MenuItem item) {

    Localelocale=null;
    switch (item.getItemId()) {
        case R.id.action_en:
            locale = newLocale("en_US");
            Toast.makeText(this, "English", Toast.LENGTH_SHORT).show();
            break;
        case R.id.action_is:
            locale = newLocale("is", "IS");
                    Toast.makeText(this, "Íslanska", Toast.LENGTH_SHORT).show();
            break;

    }

    Resourcesres= getResources();
    DisplayMetricsdm= res.getDisplayMetrics();
    Configurationconf= res.getConfiguration();
    conf.locale = locale;
    res.updateConfiguration(conf, dm);
    Intentrefresh=newIntent(this, MainActivity.class);
    startActivity(refresh);
    finish();
    returntrue;
}

Solution 3:

Solution 4:

Have you added android:configChanges="locale" in AndroidManifest.xml? I think the problem is in your AndroidManifest.xml file.

You can see example change locale on my github repository.

Post a Comment for "Change App Language In Android 5.0 Doesn't Work"