首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何让android从指定的文件中获取字符串?

如何让android从指定的文件中获取字符串?
EN

Stack Overflow用户
提问于 2014-09-01 06:30:25
回答 2查看 63关注 0票数 2

我让string.xml文件值-ar,value -fr和我想从其中一个文件中手动获得一个字符串值。例如:

代码语言:javascript
复制
R.string-ar....
R.string-fr....

我知道系统根据系统语言或应用程序语言搜索字符串。但是我想从指定的文件中获取一个字符串,而不管系统还是应用程序语言!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-09-01 06:56:09

这就是你要的

代码语言:javascript
复制
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());
}
票数 0
EN

Stack Overflow用户

发布于 2014-09-01 06:59:27

这是通过编程方式更改区域设置的,但是您需要在每个活动onCreate中调用它。

代码语言:javascript
复制
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);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25599992

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档