gpt4 book ai didi

android - 在 Android 中以编程方式更改应用程序中的语言

转载 作者:太空狗 更新时间:2023-10-29 14:25:59 26 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Change app language programmatically in Android

我想立即在我的 SettingsActivity.java 中为所有 Activity 更改语言。
并保存此选择(即使我退出应用程序或重启手机),而不管系统区域设置如何。
我该怎么做?

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.
}
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com