在我的应用程序中,我有许多活动类,我想根据Spinner Value Selected更改整个应用程序语言。请帮我。我可以通过以下代码更改单个活动语言。
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
if (pos == 1) {
Toast.makeText(parent.getContext(),
"You have selected Tamil", Toast.LENGTH_SHORT)
.show();
setLocale("ta");
} else if (pos == 2) {
Toast.makeText(parent.getContext(),
"You have selected Hindi", Toast.LENGTH_SHORT)
.show();
setLocale("hi");
} else if (pos == 3) {
Toast.makeText(parent.getContext(),
"You have selected English", Toast.LENGTH_SHORT)
.show();
setLocale("en");
}
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
}
public void setLocale(String lang) {
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, ActivityLanguage.class);
startActivity(refresh);
}
}
答案 0 :(得分:1)
-vm
// Locale locale = new Locale(&#34; ru&#34;);例如。
eclipse.exe