Question

I've read through several posts about android options menu problems, but none are helping me resolve this particular issue.

Android version: API 15 & API 16

Using the ActionBarCompat support library

I have a pager fragment with 2 fragments. The "Details" fragment will show/hide buttons based on some flag. When I first load the screen, the menu items show appropriately. When I take some action and return to the screen, my menu doesn't look like it has items in it, but has a divider bar hanging out. No buttons displayed (although they should be). If I navigate to the other tab and navigate directly back to the "Details" tab, the buttons then appear as expected.

enter image description here

I'm refreshing menu items elsewhere in my app without issue - using SupportInvalidateOptionsMenu, HasOptionsMenu = true, menu.Clear() during OnCreateOptionMenu etc etc

  1. Why isn't menu.Clear() actually clearing my menu
  2. Why aren't the menu items there, but if i simply navigate away and then back (which only triggers the OnCreateOptionsMenu / OnPrepareOptionsMenu callbacks), they are

Note -- The menu items show as expected on API 17+

Was it helpful?

Solution

Ultimately, I had two problems and didn't realize it.

  1. My AVD was bad (which caused my menu to have strange gaps in it - as pictured above). Once I deleted the AVD and built a new one, I was able to see some menu items - although the "Save" button still wouldn't re-draw
  2. There was a timing issue between when InvalidateOptionsMenu was trying to execute and when my ViewPager was trying to draw itself and send its own Invalidate calls.

This link led me to the right answer:

https://code.google.com/p/android/issues/detail?id=29472

Particularly comments #8 and #20

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