Menus Flashcards
What is a menu?
A common UI component used to present user actions and
other options in an application’s activity
What are the three fundamental types of menus?
– Options menu – Contains actions that have a global impact on an application
– Context menu – A floating menu that appears when the user performs a long-click on an element, providing actions on the selected context
– Popup menu – Displays a list of items in a vertical list that is anchored to the view that invoked the menu.
Where are menus defined
Menus and their items in Android applications should
be defined in XML under the menu resources (res/menu). These can then be inflated (loaded) in a given activity or fragment.
Why are XML menu resources used?
– They make it easier to visualize the menu structure
– They separate the menu content from an activity’s/ fragment’s code
– Allows for the creation of alternative menu configurations
for diverse platforms, screen sizes, etc.
What elements are used to build menus
<menu>
<item>
<group>
</group></item></menu>
Describe <menu>
● Defines a Menu, which is a container for menu items.
● A <menu> element must be the root node for the file and can hold one or more <item> and <group> elements.</group></item>
Describe <item></item>
● Creates a MenuItem, which represents a single item in a menu.
● This element may contain a nested <menu> element in order to create a submenu.
Describe <group></group>
● An optional, invisible container for <item> elements.
● It allows one to categorize menu items so they share properties such as active
state and visibility</item>