gpt4 book ai didi

android - 如何在运行时更改语言

转载 作者:太空狗 更新时间:2023-10-29 15:23:58 26 4
gpt4 key购买 nike

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

我试图用这种方式做主题

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

但所有更改仅在重新启动应用程序后应用谁能帮帮我?

最佳答案

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

//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);
}

关于android - 如何在运行时更改语言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4016516/

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