Admob将应用程序区域设置重置为系统默认设置 [英] Admob reset app locale to system default
问题描述
我在启动器活动中设置了一个本地语言,一两秒钟后,语言环境设置重置为设备的系统语言环境设置。
I set a local in my launcher activity, after a second or two the locale settings resets to the device's system locale settings.
经过几个小时的挖掘,我找到了罪魁祸首google admob。
在初始化它的web视图时,它会重写 Configuration
,该配置会造成混乱,包括布局,字符串等。
After several hours of digging, I found the culprit, google admob.
While initilizing it's webview it rewrites the Configuration
which creates a mess, with layouts, strings, and so on.
这里我能做什么?
推荐答案
问题是由于使用了不推荐使用的 updateConfiguration引起的
在API的版本高于17时,以下代码解决了该问题(在活动范围内),并设置了持久的区域设置。
The issue was caused by using the deprecated updateConfiguration
on API's newer than 17, the following code solves the issue (within activity), and sets a persisting locale settings.
public void attachBaseContext(Context base) {
Resources resources = base.getResources();
Locale locale = new Locale("ru");
Locale.setDefault(locale);
Configuration config = resources.getConfiguration();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
config.setLocale(locale);
base = base.createConfigurationContext(config);
}
else {
config.locale = locale;
resources.updateConfiguration(config, resources.getDisplayMetrics());
}
super.attachBaseContext(base);
}
这篇关于Admob将应用程序区域设置重置为系统默认设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!