So my problem is that when the user clicks 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 to change that title?
I have already try to use setTitle
on the click method but still not working.
To set the title for your ActionBar , while using a custom layout, in your Fragment you'll need to call getActivity(). setTitle(YOUR_TITLE) .
you can change the title by overriding the onResume method. And for the safe side, you can also override setUserVisibleHint and change the title when fragment isVisibleToUser .
Fragment can't be initiated without Activity or FragmentActivity.
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"); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With