Hide item from popupmenu

社会主义新天地 提交于 2019-11-29 13:07:47

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()

Thirumalvalavan

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");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!