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 localiz
Here is my workaround solution.
We resolved that issue by enforcing setting locale again after initializing webView and before loading content:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
MyApp.getApplication().switchToCzLocale();
}
For example in WebActivity:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web);
mWebView = (WebView) findViewById(R.id.webview);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
MyApp.getApplication().switchToCzLocale();
}
mWebView.loadData(getString(R.string.web_content), "text/html", "charset=UTF-8");
}
MyApp:
import android.app.Application;
import android.content.res.Configuration;
import java.util.Locale;
public class MyApp extends Application {
private static MyApp sApplication;
@Override
public void onCreate() {
super.onCreate();
switchToCzLocale();
sApplication = this;
}
public static MyApp getApplication() {
return sApplication;
}
public void switchToCzLocale() {
Locale mLocale = new Locale("cs","CZ");
Configuration config = getBaseContext().getResources()
.getConfiguration();
Locale.setDefault(mLocale);
config.setLocale(mLocale);
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
}
}
I hope that may help,'.
Still Im looking for a better solution.