活动标题语言的问题 [英] Troubles with activity title language
问题描述
我的应用中有两种语言. values/strings.xml 和 values-ru/strings.xml 当我以编程方式更改语言时,所有字符串均会翻译,但活动标题不变.我在所有活动中都使用
I have two language in my app. values/strings.xml and values-ru/strings.xml When I programmatically change language, all strings translating, but activity title is unchanged. I use in all Activities
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());
当我选择语言时,活动或应用程序将重新加载.
When I select language, activity or application is reloaded.
推荐答案
我用了另一种看似愚蠢但可行的方法
i used another way it seems stupid but it's work
在每个活动中,尝试从值文件中将操作栏标题设置为您的活动标题
in each activity try to set the action bar title to your activity title from values file
在我的情况下,我使用的是 sherlockactionbar
in my case i was using sherlockactionbar
所以我在 productdetails
活动的 oncreate
中添加了此代码
so i added this in oncreate
of my productdetails
activity
getSupportActionBar().setTitle(getResources().getString(R.string.title_activity_product_details));
这篇关于活动标题语言的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!