为多种语言放置不同的 string.xml 文件非常容易,例如:
English
Values
String.xml
Arabic
Values-ar
String.xml
但它仅在设备语言更改时有效。我的情况是我必须在应用程序中加载用户选择的语言,与设备中选择的语言不同,那么如何加载不同的 String.xml
文件?
最佳答案
您可以使用以下代码更改应用程序语言:
Locale locale = new Locale(languageToLoad);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
languageToLoad
是一个 String
变量,如 "en"
或 "ar"
。
关于android - 设备语言为英文时如何加载arabic string.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22439520/