written by https://stackoverflow.com/questions/35015182/different-toolbar-for-fragments-and-navigation-drawer
7 3 | Please, explain to me... I have Navigation Drawer in my | ||
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. | ||||||||
|
'모바일개발(Mobile Dev) > 안드로이드개발(Android)' 카테고리의 다른 글
using parsing round math (0) | 2017.07.16 |
---|---|
Keeping your app Awake in android (0) | 2017.07.16 |
when using imageView in camera (0) | 2017.07.08 |
how to deal activity value interaction (0) | 2017.07.08 |
how to use option menu icon each Toolbar in Fragment (0) | 2017.07.01 |