The last version of WhatsApp does what I'm talking about. When you scroll between tabs the toolbar shows different menu options. I can implement ViewPager with adapter and fragments but not this. How could it be done? I really don't know what kind of trick is behind. It changes everytime you switch pages
In each Fragment you have to override onCreateOptionsMenu
, with different menu/menu.xml
files
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.clear();
inflater.inflate(R.menu.menu, menu);
super.onCreateOptionsMenu(menu, inflater);
}
Don't forget to call setHasOptionsMenu(true);
, in onCreate of your Fragment
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With