I have a requirement to change my application language from english to Chinese.I am able to do so in many devices except Google Pixel which has Android 8.0.0. I am using the below code for this
public static void changeLocaleTo(String locale){
Resources res = App.getContext().getResources();
DisplayMetrics dm = res.getDisplayMetrics();
android.content.res.Configuration conf = res.getConfiguration();
conf.setLocale(new Locale(locale.toLowerCase())); // API 17+ only.
conf.locale = (new Locale(locale.toLowerCase()));
res.updateConfiguration(conf, dm);
//for Build>=25
//res.createConfiguration(conf, dm);
}
I have tried many things using the below links
How to programmatically change language?
https://gunhansancar.com/change-language-programmatically-in-android/
but none are able to change the language in my Pixel phone.
Please Note: However, if I change my device language from device settings, my app changes to Chinese version in Pixel too.
I have 'values-zh' folder in res having the Chinese strings.