我希望将语言更改为英语,但是当它是android 5.0.2手机时它不起作用。当它是android 7.1.1时它是正常的。这是我的代码:
public static void applyLanguage(Context context, String newLanguage) {
if (StringUtil.isEmpty(newLanguage)) {
return;
}
Resources resources = context.getResources();
Configuration configuration = resources.getConfiguration();
Locale locale = SupportLanguageUtil.getSupportLanguage(newLanguage);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
configuration.setLocale(locale);
createConfigurationResources(context, newLanguage);
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
configuration.setLocale(locale);
}else {
configuration.locale = locale;
}
DisplayMetrics dm = resources.getDisplayMetrics();
resources.updateConfiguration(configuration, dm);
}
}
但是在英语默认语言环境中,我通常会将其更改为中文。这很奇怪。有人遇到过这个问题吗?
我通过将Locale.ENGLISH更改为Locale.US解决了这个问题,因为我设置了美国的语言资源。