paul035
paul035

Reputation: 327

Navigation drawer title according to the Drawer item

I have used getSupportActionBar().setTitle("drawer_title"); and the title changes according to drawer item. But when I go back the title does not get updated. for eg: If I'm at dashboard-fragment toolbar-title is dashboard and after that when I go to message-fragment toolbar-title changes to message, but, after when I press back button it goes back to dashboard-fragment but the title does not updated to dashboard it remains message.
How could I update the title again??

Upvotes: 0

Views: 52

Answers (4)

paul035
paul035

Reputation: 327

This works for me I just used getActivity().setTitle("fragment_title"); inside onCreateView() method of fragment.

Upvotes: 0

Zain
Zain

Reputation: 40830

In your fragment use requireActivity() to get the activity to the activitiy's SupportActionBar.

So, to set the title in the fragment then use:

((AppCompatActivity) requireActivity()).getSupportActionBar().setTitle("");

Upvotes: 1

Mohamed Nageh
Mohamed Nageh

Reputation: 2043

Use getSupportActionBar().setTitle("drawer_title"); inside onResume() method of your fragment.

Upvotes: 0

Muhammad Saad Rafique
Muhammad Saad Rafique

Reputation: 3189

Add following line in onViewCreated method of your fragment:

getSupportActionBar().setTitle("Your title here");

Upvotes: 0

Related Questions