好吧,我已经报告过这个bug - https://code.google.com/p/android/issues/detail?id=235561 现在,我已经实现了这种解决方法,也许有人会觉得它有用。
首先,我们需要创建一个BroadcastReciever,将系统语言改变听:
private class LanguageChangeReceiver extends BroadcastReceiver {
public static boolean isNougatTraditionalChinese() {
return isNougat() && Locale.getDefault().toLanguageTag().contains("zh-Hant");
}
@Override
public void onReceive(Context context, Intent intent) {
if (!application.getConfiguration().isLanguageSet()) {
if (isNougatTraditionalChinese()) {
String[] supportedLangTags = context.getResources().getStringArray(R.array.language_values);
application.getConfiguration().setLanguagePreference(supportedLangTags[2]);
application.updateLanguage();
}
}
}
}
...应用语言更新中看起来大致这样...
private void updateLanguage(String langTag) {
Locale myLocale = L10nUtils.createLocaleByTag(langTag);
Resources res = getResources();
DisplayMetrics dm = res.getDisplayMetrics();
android.content.res.Configuration conf = res.getConfiguration();
conf.locale = myLocale;
res.updateConfiguration(conf, dm);
}
...和在上下文中注册BroadcastReciever ...
context.registerReceiver(new LanguageChangeReceiver(), new IntentFilter(Intent.ACTION_LOCALE_CHANGED));
请问您可以指定数组R.array.language_values和createLocaleByTag方法。谢谢! –