我想让我的应用程序多语言,我为它们使用了两个文件夹,第一个是默认的 values
在res
里面文件夹,第二个是values-ar
在res
里面文件夹。当语言是英语时,一切都很完美。
现在,我想将其更改为 arabic
.我使用了这段代码:
Locale locale = new Locale("ar");
Locale.setDefault(locale);
android.content.res.Configuration config = new android.content.res.Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());
当我使用该代码时,应用程序的指令如cut
和 paste
已更改,但我不知道该告诉应用程序使用来自 values-ar
的变量文件夹,不是来自 values
文件夹。
请不要担心编码问题
提前致谢
最佳答案
可以获取当前语言并设置if条件。
String currentLang = Locale.getDefault().getDisplayLanguage();
if(currentLang == "english"){
//TODO
}else if(currentLang == "yourLang"){
//TODO
}
希望您会发现这很有用。 干杯
关于android 使用 localse 来改变语言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17650601/