I have an Activity in which there is a TabLayout with 3 fragments. When switching to a new snippet, I need to update the menu for my toolbar. The menu is updated but not the first time. First you need a couple of times on the tabs to go, so that the menu would be updated later. Did not find information about this in google.
Here is how I update the menu:
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { menu.clear(); inflater.inflate(R.menu.fm_fragment_menu, menu); super.onCreateOptionsMenu(menu, inflater); }
setHasOptionsMenu(true)cause when creating a fragment?super.onCreateOptionsMenu(menu, inflater)does not need to be called in this method. - pavlofff