Jeison Duran Jeison Duran - 1 year ago 135
Android Question

Change ActionBar title using Fragments

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!

Answer Source

In your activity:

public void setActionBarTitle(String title) {

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

 public void onResume(){

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download