0% found this document useful (0 votes)
42 views35 pages

Lab 8

This document discusses creating interactive menus and action bars in Android applications. It covers the different types of menus like option menus, submenus, and context menus. It also discusses implementing menus through XML layout files and Java code. The document then covers using the action bar to provide navigation and functionality. It shows how to display action items, customize the action bar, and enable the action bar for different themes and SDK versions. Examples are provided of creating menus, submenus, context menus, and displaying action items on the action bar.

Uploaded by

nazia khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views35 pages

Lab 8

This document discusses creating interactive menus and action bars in Android applications. It covers the different types of menus like option menus, submenus, and context menus. It also discusses implementing menus through XML layout files and Java code. The document then covers using the action bar to provide navigation and functionality. It shows how to display action items, customize the action bar, and enable the action bar for different themes and SDK versions. Examples are provided of creating menus, submenus, context menus, and displaying action items on the action bar.

Uploaded by

nazia khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 35

Lab 08

Creating Interactive Menus and


ActionBars
By
M.Zakir Khan
In almost all applications we encounter menus that display
options in the form of menus items. Choosing a menu item
results in the initiation of the desired task.
ActionBar is a widget that replaces the title bar at the top of an
Activity displaying navigation and important functionality of an
application. It provide a constant UI of an application.
Action bar is also commonly used to provide a quick link to an
application’s home.
Menus and their Types
• Android SDK support three types of menus:
Option, submenu and Context.
Option Menu--- Also know as Activity menu, this menu is displayed when a MENU button is
clicked. In an option menu, the menu items are displayed in the form of text, checkbox and radio
buttons.
 Icon Menu
 Expanded Menu
Submenu--- Submenu refer to the menu that displays more detailed or specific menu options
when a menu item is selected. A submenu is displayed as a floating window showing all of its
menu options, the name of the submenu is shown in the header bar and each menu option is
displayed with its full text, checkbox and radio button
Context Menu--- The context menu is displayed when we tap-and-hold on the concerned View or
when a user holds the middle D-pad button or press the track ball.
Screen Shot
Default Menu + Creating Menus through XML
Java code
Defining Checkboxes and Shortcut
Adding Submenu Screen shot
Adding Submenu Xml code
Adding Submenu Java code
Context Menu
• When emulator run, Step1: first of all 3 textview will show as shown
in left figure 0ne. Step2: When you click and pressed the second
textview then the second figure will shown. Step3 when you click on
Third Textview then it will show like figure three.
Context Menu Xml Code of MainActivity+contextMenuOne+ContextMenuTwo
Context Menu Java Code
Context Menu Java Code Continue
Appling Context Menu to Listview
• We have seen the implementation of context menu to the two
textview controls. Instead of two textview control, let’s try creating a
context menu for a listview control so that when the user taps and
holds on any listview item, information about the item is displayed.
• When we pressed on Listview item it will appear Menu
Screen shot
XML and JAVA code
Java code
Java code Continue
Pop UP menu Screen Shot
Pop UP menu XML Code
Pop UP menu Java Code
Pop UP menu Example 2
Pop UP menu Example 2 XML
Pop UP menu Example 2 JAVA
Pop UP menu Example 2 JAVA Class
Using the ActionBar

• Action bar is a widget that replace the title bar at the top of every
Activity displaying navigation and important functionality of an
application.
• By default the Action bar includes the application logo on the left side,
followed by activity title, and menu items on the right side.
• It provide a constant UI of an application.
• It also used to provide a quick link to the application
Using the ActionBar Continue
Action bar provide the following features:
Customize the title bar of an activity
Follows its own life cycle.
Consistently displays frequently used actions of an application.
Appears in three standard forms: standard, tabbed, and list
Makes it possible to use the application icon or logo for navigation
Enabling the Actionbar
The action bar is enabled if an application uses default Theme.Holo theme
and whose target SDK is 11 or higher
Example
<uses-sdk android:targetSdkVersion=“13” />
Displaying Action Items
• To display menu items in the ActionBar as action item, we need to
add an android:showAsAction attribute to the menu items while
defining them in the menu file.
Always– makes the action item appear on the action bar
ifRoom--- make the action item appear in the action bar but only if
there is room available on the action bar. If there is no room then
item appear in the overflow menu
Never--- makes the menu item appear in the overflow menu
Check Manifest.xml
Displaying Action Screen Shot
How to Hide or show etc XML code
How to Hide or show etc XML code second Activity
How to Hide or show etc Java code MainActivity
How to Hide or show etc Java code second Activity

You might also like