Presentation is loading. Please wait.

Presentation is loading. Please wait.

Mobile Programmming Dr. Mohsin Ali Memon.

Similar presentations


Presentation on theme: "Mobile Programmming Dr. Mohsin Ali Memon."— Presentation transcript:

1 Mobile Programmming Dr. Mohsin Ali Memon

2 Using Action bar in Android
The action bar (ActionBar) is a menu located at the top of the activity. It can display the activity title, icon, actions which can be triggered, additional views and other interactive items. It can also be used for navigation in your application. The action bar is enabled for devices which specify a target SDK of API version 11 or higher.

3 Entries in the Action bar
Entries in the action bar are typically called actions. While it is possible to create entries in the action bar via code, it is typically defined in an XML resource file. An action bar, Provides a dedicated space for giving your app an identity and indicating the user's location in the app. Makes important actions prominent and accessible in a predictable way (such as Search). Supports consistent navigation and view switching within apps (with tabs or drop-down lists).

4 Making an action bar Each menu definition is contained in a separate file in the res/menu folder. The Android tooling automatically creates a reference to this file in the R file, so that the menu resource can be accessed. An activity adds entries to the action bar in its onCreateOptionsMenu() method.

5 mainmenu.xml file app The show As Action attribute allows you to define how the action is displayed. For example, the if Room attribute defines that the action is only displayed in the action bar if there is sufficient screen space available.

6 Inflating the menu with actions
The MenuInflator class allows to inflate actions defined in an XML file and adds them to the action bar. MenuInflator can get accessed via the getMenuInflator() method from your activity.

7 Reacting to action selection
If an action is selected, the onOptionsItemSelected() method in the corresponding activity is called. 

8 Customizing the action bar
You can change the visibility of the action bar at runtime. The following code demonstrates that. You can also change the text which is displayed alongside the application icon at runtime. The following example shows that. ActionBar actionBar = getActionBar(); actionBar.hide(); // more stuff here... actionBar.show(); ActionBar actionBar = getActionBar(); actionBar.setSubtitle(“Testing Actionbar"); actionBar.setTitle(“MY ACTIONBAR");


Download ppt "Mobile Programmming Dr. Mohsin Ali Memon."

Similar presentations


Ads by Google