Android 如何在运行时更改语言
我在这里读到关于本地化的内容: 但我需要在运行时切换android应用程序中的语言,例如通过Spinner 我试着用这种方法做主题Android 如何在运行时更改语言,android,Android,我在这里读到关于本地化的内容: 但我需要在运行时切换android应用程序中的语言,例如通过Spinner 我试着用这种方法做主题 DisplayMetrics dm = res.getDisplayMetrics(); Configuration conf = res.getConfiguration(); conf.locale = new Locale(language_code.toLowerCase(), coutry_code.toUpperCase()); res.updateCo
DisplayMetrics dm = res.getDisplayMetrics();
Configuration conf = res.getConfiguration();
conf.locale = new Locale(language_code.toLowerCase(),
coutry_code.toUpperCase());
res.updateConfiguration(conf, dm);
但所有更改仅在重新启动应用程序后适用
有人能帮我吗?在本地化指南中,它会自动更新。。。当我在应用程序中使用微调器时,它会正确更新。。你在班的最底层设置了旋转器类,对吗?或者只是在微调器的选择中,让它重新启动您的意图,如:
//spinner class start...
if(selected.equals("english") //given selected is a string returned by Spinner
{
//normal spinner content you have goes here, then
//for example, finish method, then restart with an intent
finish()
Intent myIntent = new Intent(main.this,main.class);
main.this.startActivity(myIntent);
}
//or..
if(selected.equals("french"){ // continued..
refresh();
}
//given that refresh();
public void refresh(){
finish()
Intent myIntent = new Intent(main.this,main.class);
main.this.startActivity(myIntent);
}
谢谢你,山姆!也许您可以回答如何从特定区域设置获取资源字符串?很抱歉,您需要再仔细考虑一下。。我不知道你在问什么。您是在问,如何从多个位置获取字符串?我只有几个区域设置-en、ru、fr、de。在选择设备设置(例如法语区域设置)时,我尝试调用getString(strId),返回给我的值将来自fr/strings.xml,但如果我想从另一个位置(例如英语)获取字符串,该怎么办?是否存在获取类似getString(strId,locale)的字符串的方法?