Android Popup Menu displays a Menu in a modal popup window anchored to a View. The popup will appear below the anchor view if there is room, or above it if there is not. If the IME is visible the popup will not overlap it until it is touched. Touching outside of the popup will dismiss it.
Here is a simple way to create a popup menu:
To perform an action when the user selects a menu item, you must implement the PopupMenu.OnMenuItemClickListener interface and register it with your PopupMenu by calling setOnMenuItemclickListener(). When the user selects an item, the system calls the onMenuItemClick() callback in your interface.
Step 1: Create a new project in Android Studio and name it Android popup Menu.
Step 2: Create a folder menu inside res directory if it is not already present.
Step 3: Open res -> menu and add a new menu resource file with a name
Step 4: Open MainActivity.java and replace its code with below given code.
Step 5: Open res -> layout -> activity_main.xml and replace its code with the below given code.
Step 6:Clean and run your project to see the result.