Question

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 .

Was it helpful?

Solution 2

Done by calling setMenuVisibility(true); in onResume of my Fragment class.

OTHER TIPS

Edit: With Android O, supportInvalidateOptionsMenu is deprecated. Use directly invalidateOptionsMenu()

That's correct. Android will fire onConfigurationChanged

override it and call supportInvalidateOptionsMenu();

I fixed it with a call to:

setHasOptionsMenu(true)

In the onCreateView method of the Fragment

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top