I have one MainActivity with FrameLayout and BottomNavigationView. Based on BottomNavigationView selected item I load fragments inside FragmeLayout. I have three fragments, call them A,B,C. For each of them I have defined layout xml file. For fragments A and B I don't have a toolbar but for fragment C I have defined in fragment_c.xml Toolbar( androidx.appcompat.widget.Toolbar).
- I defined menu_c.xml file with one item,
- I have added this line in Fragment_C.java
setHasOptionsMenu(true)
inonCreateView
method, - I have also added
inflater.inflate(R.menu.menu_c.xml, menu)
inonCreateOptionsMenu
method
Problem is that the menu does not apper in Fragment_C, toolbar is there but menu isn't.
I have searched for answers and couldn't find working solution. I found that for regular toolbar with options you need to call setSupportActionBar(actionBarToolBar)
from onCreate
in your main activity, but I do not want toolbar to exist through all 3 fragment, I only want toolbar in my third fragment.
I do not want to hide/show toolbar with options, Is there a way to make this work with toolbar with options in only one fragment