我遇到了同样的问题:自Android
8.0+起,我的应用程序的某些部分不再更改其语言。更新应用程序和活动上下文对我有帮助。这是MainActivity函数的示例:
private void setApplicationLanguage(String newLanguage) { Resources activityRes = getResources(); Configuration activityConf = activityRes.getConfiguration(); Locale newLocale = new Locale(newLanguage); activityConf.setLocale(newLocale); activityRes.updateConfiguration(activityConf, activityRes.getDisplayMetrics()); Resources applicationRes = getApplicationContext().getResources(); Configuration applicationConf = applicationRes.getConfiguration(); applicationConf.setLocale(newLocale); applicationRes.updateConfiguration(applicationConf, applicationRes.getDisplayMetrics());}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)