Types of menus, option menu vs context menu vs pop menu in Android Programming

Опубликовано: 23 Август 2026
на канале: Sarthak Education (CDPatel Digital Room)
1,233
25

There are three types of menus in Android: Popup, Contextual and Options. Each one has a specific use case and code that goes along with it.

Each menu must have an XML file related to it which defines its layout. These are the tags associated with the menu option:
menu - This is the container element for your menu
item - This denotes an item and is nested inside of the menu tag. Be aware that an item element can hold a menu element to represent a submenu
group - This is used to signify a certain property or feature to a couple of menu items

important attributes:
id - This is a unique identifier for the item in the menu. You can use this to see exactly which item the user clicked
icon - If you want to show an icon associated with that menu item
title - Text that will be shown in the menu for that item
showAsAction - This attribute should only be used when using a menu in an activity that uses an application bar(or as it is also referred to, the action bar). It controls when and how this item should appear as an action in the application bar. There are five values: always, never, ifRoom, withText, and collapseActionView

Options Menu
This menu is usually found at the top of your application and in it, you should place actions that affect the application as a whole. These could be the application’s settings or a search box.

Contextual Menu
This menu appears when a user performs a long click on one of your UI elements. The options found in this menu affect what UI element the user made the click on. It is common to use this type of menu in list or grid views, where the user’s interaction with each item can lead to a specific action.

Popup Menu
A popup menu is a type of menu that displays items in a vertical list. This list is attached to the view the user has clicked on to invoke this menu. It is important to keep in mind, that when choosing a popup menu, you do not want the user’s choice to affect the previous content the user pressed.