我从这个帖子Change languages in app via strings.xml获得了Android的setLocale
方法。问题是Android Studio会说locale is deprecated
,而且
updateConfiguration(android.content.res.Configuration.androidtil.DisplayMetcis) is deprecated
。
有谁知道这项工作?
/*- Set locale ------------------------------------------------------------ */
public void setLocale(String lang) {
Locale myLocale = new Locale(lang);
Resources res = getResources();
DisplayMetrics dm = res.getDisplayMetrics();
Configuration conf = res.getConfiguration();
conf.locale = myLocale;
res.updateConfiguration(conf, dm);
Intent refresh = new Intent(this, SignUp.class);
startActivity(refresh);
}
答案 0 :(得分:0)
Resources.updateConfiguration
现已弃用,请避免直接更改conf.locale
字段。从API 24使用:
conf.setLocale(locale);