Option Menu dosn't show in fragment using collapsingToolbar

For some reason my Fragment never calls onCreateOptionsMenu to inflate my menu, the overflow menu never appears and pressing the menu button in the emulator also does nothing.

And I tried to put setHasOptionsMenu(true) once in onCreateView but nothing happened after this I tried to put ((AppCompatActivity)getActivity()).setSupportActionBar(toolbar) in the same Function but nothing happened again?


Solution 1:

you have to Write both of the lines together to make it work in onCreateView Function inside your fragment. The Lines:

setHasOptionsMenu(true);
((AppCompatActivity)getActivity()).setSupportActionBar(your_toolbar);