Please, explain to me... I have Navigation Drawer in my Activity
and it syncs with Toolbar
(like ActionBar
). Activity has few fragments and in different fragments I need to use different AppBar
modes (parallax in one, simple in another). So, I think that I should set CoordinatorLayout
in each frament with AppBar and content.
But how I can replace last toolbar on new to save synchronization with Drawer? Or it's wrong way and I need make it some else?
each toolbar different navigation drawer
written by https://stackoverflow.com/questions/35015182/different-toolbar-for-fragments-and-navigation-drawer
7 3 | |||
add a comment |
0 | If you are using | ||||||||||||
|
3 | Not sure if my approach is good, but I tried to add this public method to my activity:
and I added this in all fragments:
It's working fine, but I'm not sure if it may cause a memory leak or any other performance issue. Maybe someone can help with it? | ||||||||||||||||||||
|
1 | You can access main
| ||||
|
0 | If you want to use appbar(toolbar) that you specified in navigation drawer in different fragments with, for example different options menu items, you could make a public method in Main Activity where you specified your navigation drawer logic.
Now you can use this method in your fragments to access the main toolbar and override it with your custom title, options menu... You can do this by creating a new toolbar variable in your fragment and then inflate it in onCreateView method like this
R.id.toolbar is the id of a toolbar that you specified in your layout file and it is the same id that you used in your main activity for the main toolbar. Now you can call the method setToolbar(Toolbar toolbar, String title) in fragment like this
If you want to use options menu for this fragment you have to call
in fragments onCreate() or onCreateView() methods. After that you can override method onCreateOptionsMenu() like this
You can repeat this procedure for other fragments in your navigation drawer as well. Although it worked for me, I don't know if this violates activities or fragments lifecycle or causes memory leeks. | ||||||||
|