We got a weird behavior with Android N 7.1 ( API-25 ) That after Launching WebView, system enforces reseting Locale to device locale. That overrides used locale (for localization) on application. Easy way to reproduce that is to get a localization on app. and launch a WebView. Then you won't see localized content any more until you relaunching app again. That happens only on Android-7.1 (API-25)
Here is how I switch Locale which is working in all APIs:
public void switchToCzLocale() {
Locale mLocale = new Locale("cs","CZ");// it can be any other Locale
Configuration config = getBaseContext().getResources()
.getConfiguration();
Locale.setDefault(mLocale);
config.setLocale(mLocale);
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
}
I have uploaded a sample to reproduce that issue with more details on:
https://github.com/mabuthraa/WebView-android7-issue
Please any idea if this behavior is a bug or probably bad implantation of changing locale.
Here is the link to issue ticket on Android group: Issue 218310: [developer preview] Creating a WebView resets Locale to user defaults
Here is my workaround solution.
We resolved that issue by enforcing setting locale again after initializing webView and before loading content:
For example in WebActivity:
MyApp:
I hope that may help,'.
Still Im looking for a better solution.