Hide item from popupmenu

前端 未结 2 1385
隐瞒了意图╮
隐瞒了意图╮ 2020-12-18 18:07

I created a popup menu. I need to hide a particular item from popup menu on condition, I tried this below code but it doesn\'t work and shows \"unexpectedly your app has

相关标签:
2条回答
  • 2020-12-18 18:15

    This answer may be helpful to someone,

    I used below

    popupMenu.getMenu().findItem(R.id.next).setVisible(true);
    

    If you want to change the text of the menu, you can use below code,

    popupMenu.getMenu().findItem(R.id.next).setTitle("After");
    
    0 讨论(0)
  • 2020-12-18 18:20

    You need to get the Menu Object from the PopupMenu before you get the item. So it'd be something like

    Menu popupMenu = popup.getMenu();
    if(Global.lock == true)
        popupMenu.findItem(R.id.lock_message).setEnabled(false);
    else 
        popupMenu.findItem(R.id.unlock_message).setEnabled(false);
    

    And I'd do this before you call popup.show()

    0 讨论(0)
提交回复
热议问题