Reputation: 6335
I have a activity having multiple fragments in viewpager. When I open option menu it adds menu items from particular fragment to option menu. I am using android 4.2
and has android:configChanges="orientation"
I have not added screensize
due to which activity will be created on orientation change which I want.
When I open option menu all menus including fragment menu items are shown. But if I rotate device while option menus is showing only option menu items of activity are shown. I checked it is because fragment onCreateOptionsMenu
is not called when I change orientation. How can I add fragment option menu items to already shown option menu while changing orientation .
Upvotes: 3
Views: 3795
Reputation: 585
I fixed it with a call to:
setHasOptionsMenu(true)
In the onCreateView method of the Fragment
Upvotes: 1
Reputation: 157457
Edit: With Android O, supportInvalidateOptionsMenu
is deprecated. Use directly invalidateOptionsMenu()
That's correct. Android
will fire onConfigurationChanged
override it and call supportInvalidateOptionsMenu();
Upvotes: 4
Reputation: 6335
Done by calling setMenuVisibility(true);
in onResume
of my Fragment class.
Upvotes: 1