可能重复:
在 Android 中以编程方式更改应用程序语言
我想立即更改SettingsActivity.java
所有活动中的语言。
并保存此选择(即使我退出应用程序或重新启动手机),无论系统区域设置如何。
我怎样才能做到这一点?
public class MyOnItemSelectedListener implements OnItemSelectedListener {
public void onItemSelected(AdapterView<?> parent,
View view, int pos, long id) {
switch (pos) {
case 0:
Locale locale = new Locale("en");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config, getBaseContext()
.getResources().getDisplayMetrics());
break;
case 1:
Locale locale2 = new Locale("de");
Locale.setDefault(locale2);
Configuration config2 = new Configuration();
config2.locale = locale2;
getBaseContext().getResources().updateConfiguration(config2, getBaseContext()
.getResources().getDisplayMetrics());
break;
}
}
public void onNothingSelected(AdapterView<?> parent) {
// Do nothing.
}
}