如何强制Android应用程序重新加载相应的语言更改活动标题? [英] How to force Android application to reload the activity title corresponding to the language change?

查看:621
本文介绍了如何强制Android应用程序重新加载相应的语言更改活动标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在应用程序的语言已更改怎么可能迫使Android应用程序重新加载活动的标题?为了您的信息,应用程序重新加载,只有当设备旋转的称号。然而,活动的内容重新装入相应的语言内容没有问题,但活动标题!

How could force android application to reload activity title when the language of the application has been changed? For your information, the application reloads the title only when the device is rotated. Yet, the content of the activity is reload with the appropriate language content with no problem, but the activity title!

在AndroidManifest.xml文件,安卓。configChanges =语言环境已经被加入,但没有成功。

In AndroidManifest.xml file, android:configChanges="locale" has been added with no success.

<activity
    android:name=".layout.MainActivity"
    android:configChanges="locale"
    android:label="@string/app_name" />

甚至压倒一切的onConfigurationChanged事件不能正常工作,

Even overriding onConfigurationChanged event does not work,

@Override
public void onConfigurationChanged(Configuration newConfig) {
    // refresh your views here
    super.onConfigurationChanged(newConfig);

    this.setTitle(getResources().getString(R.string.app_name));
}

感谢您,

推荐答案

同样的问题,通过强制标签的ActionBar在重装解决活动的onCreate 方法:

Same problem, solved by forcing ActionBar label reload in Activity onCreate method:

    PackageManager pm = getPackageManager();
        try {
            ActivityInfo ai = pm.getActivityInfo(this.getComponentName(), PackageManager.GET_ACTIVITIES|PackageManager.GET_META_DATA);
            if (ai.labelRes != 0) {
                getSupportActionBar().setTitle(ai.labelRes);
            }
        } catch (PackageManager.NameNotFoundException e) {
            e.stacktrace();
        }

这篇关于如何强制Android应用程序重新加载相应的语言更改活动标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆