gpt4 book ai didi

java - 多语言应用程序问题

转载 作者:行者123 更新时间:2023-12-02 04:01:09 28 4
gpt4 key购买 nike

首先,我在 LanguageActivity.java 中遇到了一些问题。假设我从微调器中选择“zh”,它应该将 strings.xml 更改为“zh”。但是我发现我的中有些字符串接口(interface)不会更改为 [zh]strings.xml。

Settings Does not change to chinese

这是我的 LanguageActivity.java 代码

             @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_language);
spinnerctrl = (Spinner) findViewById(R.id.spinner1);
spinnerctrl.setOnItemSelectedListener(new OnItemSelectedListener() {

public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {

if (pos == 1) {

Toast.makeText(parent.getContext(),
"You have selected English", Toast.LENGTH_SHORT)
.show();
setLocale("en");
} else if (pos == 2) {

Toast.makeText(parent.getContext(),
"You have selected ", Toast.LENGTH_SHORT)
.show();
setLocale("zh");
} else if (pos == 3) {

Toast.makeText(parent.getContext(),
"You have selected Hindi", Toast.LENGTH_SHORT)
.show();
setLocale("hi");
}
else if (pos == 4) {

Toast.makeText(parent.getContext(),
"You have selected Malay", Toast.LENGTH_SHORT)
.show();
setLocale("ms");
}

}

public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Nothing to select", Toast.LENGTH_LONG).show();
}

});
}

public void setLocale(String lang) {
Resources res = getResources();
DisplayMetrics dm = res.getDisplayMetrics();
Configuration conf = res.getConfiguration();
if (!conf.locale.getLanguage().equals(lang)) {
conf.locale = new Locale(lang);
res.updateConfiguration(conf, dm);
Intent refresh = new Intent(this, LanguageActivity.class);
startActivity(refresh);
finish();
}
}

最佳答案

要应用区域设置更改,您必须重新启动应用程序。

试试这个:

Intent i = getBaseContext().getPackageManager()
.getLaunchIntentForPackage( getBaseContext().getPackageName() );
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);

希望有帮助。

关于java - 多语言应用程序问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34870269/

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