trainingtrains Logo

91-9990449935

 0120-4256464

Android Popup Menu Example

Android Popup Menu displays the menu below the anchor text if space is available otherwise above the anchor text. It disappears if you click outside the popup menu.

The android.widget.PopupMenu is the direct subclass of java.lang.Object class.

Android Popup Menu Example

Let's see how to create popup menu in android.

activity_main.xml

It contains only one button.

File: activity_main.xml

popup_menu.xml

It contains three items as show below. It is created inside the res/menu directory.

File: poupup_menu.xml

Activity class

It displays the popup menu on button click.

File: MainActivity.java


Output:

android popup menu example output 1 android popup menu example output 2 android popup menu example output 3