我的应用程序中有两种语言。值/strings.xml and 值-ru/strings.xml当我以编程方式更改语言时,所有字符串都会翻译,但活动标题不变。我在所有活动中使用
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
String languageToLoad = prefs.getString("prefLanguage","en");
Locale locale = new Locale(languageToLoad);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());
当我选择语言时,活动或应用程序会重新加载。
我用了另一种方式,看起来很愚蠢,但它有效
在每个活动中尝试将操作栏标题设置为值文件中的活动标题
就我而言,我正在使用sherlockactionbar
所以我添加了这个oncreate
of my productdetails
活动
getSupportActionBar().setTitle(getResources().getString(R.string.title_activity_product_details));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)