gpt4 book ai didi

android - Activity 标题语言问题

转载 作者:IT王子 更新时间:2023-10-28 23:29:41 26 4
gpt4 key购买 nike

我的应用中有两种语言。 values/strings.xmlvalues-ru/strings.xml 当我以编程方式更改语言时,所有字符串都在翻译,但 Activity 标题未更改。我在所有 Activity 中使用

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());

当我选择语言时,重新加载 Activity 或应用程序。

最佳答案

我用了另一种方法,它看起来很愚蠢,但它有效

在每个 Activity 中尝试将操作栏标题设置为值文件中的 Activity 标题

就我而言,我使用的是 sherlockactionbar

所以我在 productdetails Activity 的 oncreate 中添加了这个

    getSupportActionBar().setTitle(getResources().getString(R.string.title_activity_product_details));

关于android - Activity 标题语言问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22884068/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com