Android Context Menu ExampleAndroid context menu appears when user press long click on the element. It is also known as floating menu. It affects the selected content while doing action on it. It doesn't support item shortcuts and icons. Android Context Menu ExampleLet's see the simple example of context menu in android. activity_main.xmlDrag one listview from the pallete, now the xml file will look like this: File: activity_main.xml
main_menu.xmlCreate a separate menu_main.xml file in menu directory for menu items. Activity classLet's write the code to display the context menu on press of the listview. File: MainActivity.java
Output:![]() Output after long press on the listview. ![]() Output after clicking on the context menu. ![]()
Next TopicAndroid Popup Menu Example
|
JavaTpoint offers too many high quality services. Mail us on h[email protected], to get more information about given services.
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected].
Duration: 1 week to 2 week