When and how often is the onPrepareOptionsMenu() method called for ActionBar?

前端 未结 2 1971
甜味超标
甜味超标 2020-12-14 15:56

It is clear for Activities - the method is being called right before the menu is shown. But what about ActionBar when it is always shown

2条回答
  •  醉梦人生
    2020-12-14 16:31

    Use invalidateOptionsMenu() to trigger onPrepareOptionMenu() method as suggested by document.

    On Android 3.0 and higher, you must call invalidateOptionsMenu() when you want to update the menu, because the menu is always open. The system will then call onPrepareOptionsMenu() so you can update the menu items.

提交回复
热议问题