android语言文件夹为两种不同的语言

时间:2014-12-03 05:15:28

标签: android multilingual

我的应用中有两种语言。英语和乌尔都语。我为strings.xml创建了两个文件夹 1.values(英语默认)
2.values-ar(乌尔都语)

现在,当我将Locale设置为英语时,它在手机和平​​板电脑上运行良好。但是当我将语言环境设置为urdu然后在手机中显示urdu文本但在平板电脑中显示英语。

请解释为什么会这样。 根据我的理解,应用程序应该在语言环境集的基础上选择字符串。

Here they haven't specified anything about phone and tablet

感谢。

2 个答案:

答案 0 :(得分:1)

ar适用于阿拉伯语。

尝试使用值ur ur urd

答案 1 :(得分:0)

尝试使用此代码定义本地化:

Locale locale = new Locale("ar_UR");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config, 
        getBaseContext().getResources().getDisplayMetrics());

您的资源文件夹(values-ar)没有错,您只需要定义上面的代码即可。如果"ar_UR"无效,请尝试在Google中查找本地化代码。格式为:

ar =国家/地区代码(小写文字)

_ =这两个代码的分隔符

UR =语言代码(大写文字)