After calling NavigationUI.setupActionBarWithNavController
, the title of the toolbar automatically changes to the android:label
of the fragment defined in the navigation graph. But what if I want to show different buttons on the right side of the toolbar depending on the fragment? I used to create separate activities so I did not have to change the toolbar buttons dynamically, but now we use multiple logical screens (fragments) within one Activity, the buttons need to be changed just like the title.
For example, suppose my navigation has two fragments, f1 and f2. I want to show an "About" button for f1, and "Save" for f2. Is there an automatic way as the title, or do I have to manually do that in the Activity by using such methods as in (How can I dynamically create menu items?)?