onPrepareOptionsMenu in Fragment not being called

2019-04-29 17:45发布

问题:

We have an app that uses AppCompatActivity with multiple fragments, each of which contribute to the options menu. (i.e. the fragments override onCreateOptionsMenu and insert their own menu items)

The fragments also override onPrepareOptionsMenu, in order to conditionally enable/disable certain menu items based on the state of the app.

Prior to the updated version (22) of appcompat, the onPrepareOptionsMenu function was called for each fragment, and everything was working correctly. But now, it's no longer being called.

This behavior is only present in API 10. In newer APIs it works correctly. Any ideas?

回答1:

With a little digging, I found this: https://code.google.com/p/android/issues/detail?id=170630

Let's hope this is resolved in the next release of appcompat!