我让string.xml文件值-ar,value -fr和我想从其中一个文件中手动获得一个字符串值。例如:
R.string-ar....
R.string-fr....我知道系统根据系统语言或应用程序语言搜索字符串。但是我想从指定的文件中获取一个字符串,而不管系统还是应用程序语言!
发布于 2014-09-01 06:56:09
这就是你要的
Locale current = getResources().getConfiguration().locale;
Locale newlocale = new Locale("fr");
setLocale(newlocale );
String value = getResources().getString(R.string.username);//fr string
setLocale(current );
public void setLocale(Locale locale){
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());
}发布于 2014-09-01 06:59:27
这是通过编程方式更改区域设置的,但是您需要在每个活动onCreate中调用它。
Resources res = context.getResources();
// Change locale settings in the app.
DisplayMetrics dm = res.getDisplayMetrics();
android.content.res.Configuration conf = res.getConfiguration();
conf.locale = new Locale(language_code.toLowerCase());
res.updateConfiguration(conf, dm);https://stackoverflow.com/questions/25599992
复制相似问题