Android Menus - Summarized
This blog will be a kind of reminder about Android menus. I will try to summarize as much as possible. I will focus on what they are and how we implement them.
Menus can contain group
or a submenu
.
Group
You can have checkbox or radio button behavior by settingcheckableBehavior
of group item.
single
Only one item from the group can be checked (radio buttons)all
All items can be checked (checkboxes)none
No items are checkable
By using group
, you can;
- Show or hide all items with
setGroupVisible()
- Enable or disable all items with
setGroupEnabled()
- Specify whether all items are checkable with
setGroupCheckable()
You can see group example in Option Menu as Option 1 & Option 2.
Submenu
You can create a submenu by adding menu item in your current menu.xml.
You can see submenu example in Option Menu as File — New & Open
There are 3 menu options;
- Option Menu
- Contextual Menu | Floating Context Menu — Contextual Action Mode
- Popup Menu
Option Menu
Xml
Code
Contextual Menu
Floating Context Menu
Xml
Code
We have to register our views which we want to show floating menu when they are long pressed.
Contextual Action Mode
Xml
Code
Popup Menu
Xml
Code
To get more details;