How can I refresh the ActionBar when onPrepareOptionsMenu switched menu entries?

后端 未结 10 1423
予麋鹿
予麋鹿 2020-12-02 12:05

Within my apps I often enable/disable menu entries and do make them visible from onPrepareOptionsMenu.

Today I started to add the android:showAsAction menu attribute

10条回答
  •  隐瞒了意图╮
    2020-12-02 12:42

    Based on "Klaasvaak" answer above. I am using its subMenus. This works for me :

    // Declare and save the menu as global, so it can be called anywhere.
    Menu absTopSubMenus;
    
    public boolean onCreateOptionsMenu(Menu menu) {
    
    absTopSubMenus = menu;  // Used for re-drawing this menu anywhere in the codes.
    
    // The remainder of your code below
    }
    

    Then, to re-draw this, just call :

    // Redraw the top sub-menu
    absTopSubMenus.clear();
    onCreateOptionsMenu(absTopSubMenus);
    

提交回复
热议问题