我想将语言从英语更改为阿拉伯语。如果我选择阿拉伯语意味着所有文本都应该更改。但是操作栏和导航抽屉中的文本没有改变。如何更改操作栏和导航中的语言抽屉。我试过这样的事情。
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Configuration config = new Configuration();
switch (spinner.getSelectedItemPosition()) {
case 0:
changeLocale(Emp_LocalizationActivity.this,"en");
break;
case 1:
changeLocale(Emp_LocalizationActivity.this,"ar");
break;
default:
config.locale = Locale.ENGLISH;
break;
}
Intent i= new Intent(Emp_LocalizationActivity.this,Emp_Home.class);
startActivity(i);
}
});
public static void changeLocale(Activity activity, String language)
{
final Resources res = activity.getResources();
final Configuration conf = res.getConfiguration();
if (language == null || language.length() == 0)
{
conf.locale = Locale.getDefault();
}
else
{
final int idx = language.indexOf('-');
if (idx != -1)
{
final String[] split = language.split("-");
conf.locale = new Locale(split[0], split[1].substring(1));
}
else
{
conf.locale = new Locale(language);
}
}
res.updateConfiguration(conf, null);
}
`