Beruflich Dokumente
Kultur Dokumente
1. Options Menu.
2. Context Menu.
3. Contextual action bar.
4. Popup Menu.
Uses of Menus
Step 1. Start New Project Step 2. Create Menu Resource Directory Step 3. Only change “Resource Type” to menu
Step 4. Click ok Step 5. Create menu resource file in menu resource Step 6. Name the file and click ok
Adding Items To (Options) Menu Resource
Step 1. Open the menu resource file recently created Step 2. Add desired items in the menu resource.
“optional.xml”
Inflate Menu Resource
■ Open Java file (Backend File of activity).
■ Place the cursor outside the body of “onCreate()” and add “onCreateOptionsMenu()”
function.
■ Android context menu appears when user press long click on the element.
■ It is also known as floating menu.
■ It is useful to implement an actions that effect the selected content or context
frame.
■ It doesn't support item shortcuts and icons.
■ The android Context Menu is more like the menu which displayed on right click in
Windows or Linux.
■ Implementing the context menu is straightforward, and is a key ingredient in many
applications.
How to create an Context Menu?
Step 1. Create menu resource file in menu resource Step 2. Name the file and click ok Step 3. Add desired items in the menu
resource.
Register View for Context menu
■ Open Java file (Backend File of activity).
■ Create Object of any view(to which the menu is to be applied) and assign id.
■ “registerForContextMenu(View v)” function is used to register specific view for
context menu.(inside OnCreate())
■ onCreateContextMenu(): This method is used to specify the Context menu for a view.
Menu resource file (defined in XML) can be inflated into menu
– menu: Context menu : the Contect menu that is being built.
– v : View: view for which the context menu is being built.
– menuInfo: ContextMenu.ContextMenuInfo:Extra information about the item for
which the context menu should be shown.
■ menu.setHeaderTitle(): This method is used to set the header of context menu.
■ onContextItemSelected(): This method is called, when an item in the options menu is
selected. It specifies some action that is to be performed whenever an item is
clicked.