Android PopUp Menu
PopUp Menu:
A Popup Menu in Android is a type of context menu that is displayed as a floating menu whenever it is long clicked or a view is tapped. It is often used to supply actions associated with the context in relation to the given view or item.
Popup Menus allow a lot of flexibility and can be attached to specific views and are among top choice of UI elements when you need to show a list of options or actions.
Example:
// popup_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/item1"
android:title="Apple"/>
<item android:id="@+id/item2"
android:title="Orange"/>
<item android:id="@+id/item3"
android:title="Banana"/>
<item android:id="@+id/item4"
android:title="Grapes"/>
<item android:id="@+id/item5"
android:title="Mango"/>
<item android:id="@+id/item6"
android:title="Lichi"/>
</menu>
// activity_pop_up_menu_example.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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=".PopUpMenuExample"
android:padding="16dp"
android:gravity="center">
<Button
android:id="@+id/show_popup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Show Popup"
android:textColor="@color/colorWhite"
android:background="@color/colorPrimaryDark"
/>
</LinearLayout>
Output