问题
My application set locale according to selected language in application. Up to Kitkat my code works fine. After update to Lollipop locale was not set. Here i paste my code to set locale..
Locale locale = new Locale("de_DE");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config, null);
回答1:
You have to change the way of the locale initialization. From this:
Locale locale = new Locale("de_DE");
to this:
String language = "de";
String country = "DE";
Locale locale = new Locale(language , country);
Check out the full response here https://stackoverflow.com/a/27490553/2659558
Cheers!
回答2:
you can set locale to application by using following code.
Locale locale = new Locale("de", "DE");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config, null);
回答3:
Check out Lollipop Set Default local does not work Try using just the language code "de" rather than "de_DE".
回答4:
you can use this code:
public static final String COUNTRY_EN = "GB";
public static final String LANG_EN = "en";
country=COUNTRY_EN ;
lang=LANG_EN ;
Locale myLocale = new Locale(lang, country);
Locale.setDefault(myLocale);
Resources res = context.getResources();
DisplayMetrics dm = res.getDisplayMetrics();
Configuration conf = res.getConfiguration();
conf.setLayoutDirection(myLocale);
conf.locale = myLocale;
res.updateConfiguration(conf, dm);
来源:https://stackoverflow.com/questions/27164579/locale-not-set-programatically-in-android-5-0-lollipop