I use this code to set the default language manually in multiple languages app:
public static void setLanguage(Context context, String languageCode){
Locale locale = new Locale(languageCode);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale; // Deprecated !!
context.getApplicationContext().getResources().updateConfiguration(config,
context.getResources().getDisplayMetrics());
}
so now we cant set locale by config.locale is deprecated because the variable is going to be removed in API 24.
So i saw that the alternative is to set:
config.setLocales();
locale
Added in API level 1
Locale locale
This field was deprecated in API level 24. Do not set or read this directly. Use getLocales() and setLocales(LocaleList). If only the primary locale is needed, getLocales().get(0) is now the preferred accessor.
Current user preference for the locale, corresponding to locale resource qualifier.
I noticed also that there is setLocale(Locale)
as well but for api 17 and above
I checked the setLocales(LocalList) documentation and it is marked in grey as if it is also deprecated !
so what can be solution for this !?