Lollipop Set Default local not working

This method works for me on most versions of the Android API to install the application using the language (strings, etc.)

protected void setDefaultLocale(Context context, Locale locale) { Locale.setDefault(locale); Configuration appConfig = new Configuration(); appConfig.locale = locale; context.getResources() .updateConfiguration(appConfig, context.getResources().getDisplayMetrics()); System.out.println("trad" + locale.getLanguage()); } @Override protected void onCreate(Bundle savedInstanceState) { SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); String language = sharedPref.getString("pref_language", "he_IL"); if (!language.equals("")) setDefaultLocale(this, new Locale(language)); super.onCreate(savedInstanceState); } 

When using this on a working device with a lollipop, nothing changes.

Does anyone know how to solve this?

+8
android android-5.0-lollipop
source share
3 answers

Finally found the answer.

The answer was to use "iw" instead of he_il.

String language = sharedPref.getString ("pref_language", "iw");

0
source share

The answers above work, but only for the language, if you want to use, for example:

 NumberFormat numberFormat = NumberFormat.getCurrencyInstance(Locale.getDefault()); 

changes the previously installed locale, does not work anymore, as in previous versions of Android.

Changed the way the language standard is initialized (I don’t know why, I looked in the API and said nothing).

So, change the way you initialize your locale:

 Locale locale = Locale("en_US") 

:

 Locale locale = new Locale("en", "US"); 

and it works like a charm :)

Hope this helps someone in the future.

Greetings

+23
source share

I noticed a similar behavior in lollipop, but not in previous versions of the API.

In my case, the problem was that I installed, like you, the language code and country code, but my resource folders were language specific, only "values-fr" and "values-es", etc.

If you install this line

 String language = sharedPref.getString("pref_language", "he_IL"); 

to

 String language = sharedPref.getString("pref_language", "he"); 

Does it work as expected?

I only need the language code, so the setup just for this is solved for me.

+2
source share

All Articles