You are on page 1of 7

UNIT 5

MENUS, NOTIFICATION AND ACTION BAR


ANDROID MENUS
 In android, Menu is an important part of UI component

 used to provide some common functionality around the application.

 In order to use menu, we should define it in separate XML file

 use that file in our application based on our requirements.


MENU IN XML FILE
 XML format for type of menus to define menu items

  we should create a new folder menu inside of our project directory (res/menu)

 <menu> It is the root element which helps in defining Menu in XML file and it also
holds multiple elements.
 <item> It is used to create a single item in menu. It also contains nested <menu>
element in order to create a submenu.
 <group> It is an optional and invisible for <item> elements to categorize the menu
items so they can share properties like active state, visibility.
SAMPLE MENU XML FILE
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/mail"
        android:icon="@drawable/ic_mail"
        android:title="@string/mail" />
    <item android:id="@+id/upload"
        android:icon="@drawable/ic_upload"
        android:title="@string/upload"
        android:showAsAction="ifRoom" />
    <item android:id="@+id/share"
        android:icon="@drawable/ic_share"
        android:title="@string/share" />
</menu>
MENU WITH SUBMENU
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http:// schemas.android.com/apk/res/android">
<item android:id="@+id/file"
android:title="@string/file" >
<!-- "file" submenu -->
<menu>
<item android:id="@+id/create_new"
android:title="@string/create_new" />
<item android:id="@+id/open"
android:title="@string/open" />
</menu>
</item>
</menu>
OPTIONS MENU
 Options menu and app barThe options menu is the primary collection of
menu items for an activity. It's where you should place actions that have a
global impact on the app, such as "Search," "Compose email," and
"Settings."
CONTEXT MENU
 A context menu is a floating menu that appears when the user performs a
long-click on an element. It provides actions that affect the selected content
or context frame

 The contextual action mode displays action items that affect the selected


content in a bar at the top of the screen and allows the user to select multiple
items.

You might also like