android - 更改 ActionBar 标题

标签 android android-fragments android-actionbar

我的主要 Activity 由一个 fragment 组成。我在 Activity 的 onResume() 方法上设置操作栏标题为

@Override
    protected void onResume() {
        super.onResume();
        getActionBar().setTitle("My Account");
    }

将操作栏标题显示为 “我的帐户”。当我调用 fragment 时,我将 fragment 的 onResume() 方法上的标题设置为

@Override
    public void onResume() {
        super.onResume();
        getActivity().getActionBar().setTitle("Connected Accounts");
    }

将标题显示为 'Connected Accounts'。但是,当我返回 Activity 时,它仍将标题显示为 'Connected Accounts',而它应该显示作为 “我的帐户”。 请帮助我知道在这种特殊情况下缺少一些东西。谢谢

最佳答案

只需覆盖您的 fragment 类中的 onDetach() 即可。 在您的 fragment 中添加此代码。

@Override
public void onDetach() {
    // TODO Auto-generated method stub
    super.onDetach();
    getActionBar().setTitle("My Account");
}

关于android - 更改 ActionBar 标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26059521/

相关文章:

java - 如何更改 ViewPager 幻灯片上 fragment 的内容?

java - ListFragment IllegalStateException : “The content of the adapter has changed but ListView did not receive the notification”

android - Android 操作栏中的三个点设置菜单未出现

java - 更改 actionBar 下拉菜单背景颜色

android - 动态更改按钮上的 Imageview

java - 将硬编码文件解密为 byte[]

java - 我需要将谷歌地图的数据返回到我的 Activity

android - 由 : java. lang.ClassNotFoundException 引起:在路径 DexPathList 上找不到类 "com.crashlytics.android.beta.Beta"

android - 在 Fragment Kotlin 中调用 DialogFragment

android - 仍然需要使用 ActionBarSherlock 吗?