Reputation: 327
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
Reputation: 327
This works for me I just used getActivity().setTitle("fragment_title");
inside onCreateView() method of fragment.
Upvotes: 0
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
Reputation: 2043
Use getSupportActionBar().setTitle("drawer_title");
inside onResume()
method of your fragment.
Upvotes: 0
Reputation: 3189
Add following line in onViewCreated method of your fragment:
getSupportActionBar().setTitle("Your title here");
Upvotes: 0