如何在运行时更改语言

时间:2010-10-25 16:07:30

标签: android

我在这里读过有关本地化的内容:http://developer.android.com/guide/topics/resources/localization.html 但是我需要在运行时在我的android应用程序中切换语言,例如通过Spinner。

我试图以这种方式做subj

DisplayMetrics dm = res.getDisplayMetrics();
Configuration conf = res.getConfiguration();
conf.locale = new Locale(language_code.toLowerCase(),
coutry_code.toUpperCase());
res.updateConfiguration(conf, dm);

但所有更改仅在重新启动应用后才适用 有谁可以帮助我?

1 个答案:

答案 0 :(得分:0)

在本地化指南中,它会自动更新...当我在我的应用程序中使用微调器时,它会正确更新...你在类的底部设置了微调器类吗?或者只是在你的微调器的选择中,重新启动你的意图,如:

//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);
}
相关问题