3

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);
Jared Burrows
  • 54,294
  • 25
  • 151
  • 185
NSK
  • 251
  • 3
  • 10

4 Answers4

7

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!

Community
  • 1
  • 1
Marco Hernaiz
  • 5,830
  • 3
  • 27
  • 27
1

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);
Rao
  • 20,781
  • 11
  • 57
  • 77
NSK
  • 251
  • 3
  • 10
0

Check out Lollipop Set Default local does not work Try using just the language code "de" rather than "de_DE".

Community
  • 1
  • 1
0

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);
Milad Mohamadi
  • 127
  • 1
  • 10