Introduction
This article explains PopUp menus in Android. Android Studio is used to create the sample.
A PopUp menu is a type of menu that contains a menu and displays that menu below the anchor text if space is available. If the space is not available then it displays it above the Anchor text. It appears untill when you do not click on the pop-up menu text.
For this you need to create an XML file inside "res/menu/popup" like this:
- <menu xmlns:android="http://schemas.android.com/apk/res/android" >
- <item
- android:id="@+id/one"
- android:title="Android"/>
- <item
- android:id="@+id/two"
- android:title="BlackBerry"/>
- <item
- android:id="@+id/three"
- android:title="Apple"/>
- </menu>
Step 1
Create a project like this:
Step 2
Create an XML file with this:

- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context=".MainActivity"
- android:background="#fdacbd">
- <Button
- android:id="@+id/button"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentLeft="true"
- android:layout_alignParentTop="true"
- android:layout_marginLeft="110dp"
- android:layout_marginTop="80dp"
- android:text="Show Popup" />
- </RelativeLayout>
Step 3
Create another XML file with this:
- <menu xmlns:android="http://schemas.android.com/apk/res/android" >
- <item
- android:id="@+id/one"
- android:title="Android"/>
- <item
- android:id="@+id/two"
- android:title="BlackBerry"/>
- <item
- android:id="@+id/three"
- android:title="Apple"/>
- </menu>
Step 4
Create a Java class file and with the following.


Ramya PPosted Mar 21, 2014, 3:55 AM
can you tell me how to add sub items item, i.e, how can i add submenu to popupmenu item, if you know pls tell me