Android更改语言

时间:2012-04-15 13:54:28

标签: android onchange

我有两个文件:strings.xml(我的母语)和string2.xml(英语)。 有没有办法在按钮点击时加载其中一个文件?

例如,如果我使用文件strings.xml,则在按钮上单击,然后将默认值更改为string2.xml。或者,如果我使用string2.xml,则点击更改为string.xml

3 个答案:

答案 0 :(得分:1)

Resources res = context.getResources();
DisplayMetrics dm = res.getDisplayMetrics();
android.content.res.Configuration conf = res.getConfiguration();
conf.locale = new Locale(language_code.toLowerCase());
res.updateConfiguration(conf, dm);

使用上面的代码更新应用的区域设置。只需在res中有两个文件夹作为values-en和values-yournativelanguge,并将string.xml放在名为string.xml的每个文件夹中。

请参阅此LINK

答案 1 :(得分:1)

对于使用多种语言,您可以使用本地化概念。

以下是developer.android.com的链接

http://developer.android.com/resources/tutorials/localization/index.html

答案 2 :(得分:0)

关注Load different strings.xml resource on Spinner change 看起来这是可能的,但您必须更改应用程序的整个语言环境语言。