使用片段更改标题的ActionBar [英] Change ActionBar title using Fragments

查看:161
本文介绍了使用片段更改标题的ActionBar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先让我解释什么,所以你们可以更好地理解我的问题:


  • 我使用的动作条。

  • 我有一个片段通话收藏在那里我节省一些联系人作为收藏夹。

  • 当您在一个联系人点击它带我到另一个片段的把联系号码上EDITTEXT。

  • 新的片段是呼叫转移。

所以我的问题是,当用户点击带我到另一个片段,但标题操作栏上仍与最喜欢的标题,而不是新的接触,我怎么能实现改变这种标题<? / p>

我已经尝试使用上的setTitle点击方法,但仍然没有工作。

非常感谢!
对不起,我的英文不好!


解决方案

在您的活动:

 公共无效setActionBarTitle(字符串名称){
    getSupportActionBar()的setTitle(职称)。
}

而在你的片段(你可以把它的onCreate或onResume):

 公共无效onResume(){
        super.onResume();    //设置标题栏
    ((MainFragmentActivity)getActivity())
            .setActionBarTitle(您的标题);}

First let me explain something, so you guys can understand better my problem:

  • I'm using actionbar.
  • I have a Fragment call Favorites where i save some contacts as favorites.
  • When you click on one contact it takes me to another fragment an put the contact number on a editText.
  • The new fragment is call Transfers.

So my problem is that when the user click the contact that takes me to the other fragment but, the title on the action bar still with the favorite title and not the new one, how can i achieve to change that title?

I have already try to use setTitle on the click method but still not working.

Thanks so much! Sorry for my bad english!

解决方案

In your activity:

public void setActionBarTitle(String title) {
    getSupportActionBar().setTitle(title);
}

And in your fragment (You can put it onCreate or onResume):

 public void onResume(){
        super.onResume();

    // Set title bar
    ((MainFragmentActivity) getActivity())
            .setActionBarTitle("Your title");

}

这篇关于使用片段更改标题的ActionBar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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