Search This Blog

Saturday 14 July 2012

Basics about Menu in Android

Menus in Android 


Menu is the basic navigation method for an application which provides an interactive way to interact with user interface and defines the application actions for its users.


In Android version 2.3.X (API level 10) the Menu is the basic building block of the application invoked by the system when user press the menu button on device. In later versions from Android 3.0 on-wards this is replaced by an action bar on the top of device.


Android defines the three type of menus for applications

Option Menu

The option menu is the primary collection of action items for an application. If you are developing an application for android devices running the Android 2.3.X or lower version then option menu will be created by the system when ever user press the menu button on device. 


The Android 3.0 converts this into more effective method using the action bar.

Contextual Menu

A contextual menu is a floating menu invoked when user performs a long click on an element of the view.

Popup Menu

A popup menu displays a list of items in a vertical list that's anchored to the view that invoked the menu.

You can define the menus in your android application as XML resources which could be inflate in your activity or fragment.

See here a sample file defining a menu for an application

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/myaction1"
          android:icon="@drawable/ic_myaction1"
          android:title="@string/myaction1"
          android:showAsAction="ifRoom"/>
    <item android:id="@+id/help"
          android:icon="@drawable/ic_help"
          android:title="@string/help" />
</menu>



No comments:

Post a Comment