Android Context Menu
Context Menu:
In the Android context, a Context Menu can be described as a floating menu that emerges when a user employ the right mouse click or carries out a long press on a given view or area in an application.
It offers choices based on the view or context extracted about the application when the view was chosen.
The context menu is typically used to display actions resulting from the long press or right click of the selected item, which relate to the content or function for the selected element.
Example:
// context_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"/>
</menu>
// activity_context_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=".ContextMenuExample"
android:orientation="vertical"
android:padding="16dp"
android:gravity="center">
<TextView
android:id="@+id/longpress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Long Press Here"
android:textSize="30sp"
android:textColor="@color/colorOrange"
android:textStyle="bold"
android:gravity="center"/>
</LinearLayout>
Output