1

I have a collapsing toolbar in my fragment and fragment has its own toolbar. The onCreateOptionsMenu is not being called. This worked when fragment was using activity's toolbar, now while refactoring toolbar, so that each fragment has its own, onCreateOptionsMenu is not being called.

setHasOptionsMenu(true); is already there in onCreate.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Gauri Gadkari
  • 237
  • 4
  • 12
  • did you add a different onCreateOptionsMenu for each fragment? Also, where did you call setHasOptionsMenu? in the activity or in the fragment? – Levi Moreira Apr 30 '18 at 21:20
  • setHasOptionsMenu is in the fragment. – Gauri Gadkari Apr 30 '18 at 21:30
  • another fragment (which does not have a collapsingToolbarLayout) has menu and the menu is created for that one, I debugged and saw that onCreateOptionsMenu for the other fragment is being called. Also if I comment out the collapsingToolbarLayout code (the entire coordinator layout) onCreateOptionsMenu is called and menu is created. – Gauri Gadkari Apr 30 '18 at 21:33
  • refer this , https://stackoverflow.com/questions/8308695/android-options-menu-in-fragment?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – Radhey May 01 '18 at 05:05

0 Answers0