Open Android options menu from method
I know that it's possible because I've done it before, but i los开发者_JAVA百科t my code. I want to open the Menu from an touch event. What do I need to write to open it? I really don't know anymore.
You need to override onCreateContextMenu(ContextMenu, View, ContextMenu.ContextMenuInfo)
and onContextItemSelect()
in activity.
If you want it to appear on long click then call registerForContextMenu(View)
. If you want to show it manually on clicking any view then call openContextMenu()
in onClick().
精彩评论