Directory (?) [-]
- The hidden and reality of Actionbar
- Actionbar's action icon area
The hidden and reality of Actionbar
ActionBar bar = Getactionbar ();
Bar. hide (); Hide Action Bar
Bar. Show (); Show Action Bar
Actionbar's action icon area
The right side of the Actionbar is the Action icon area, as shown in
This is the menu area of the Actionbar, which, as part of the Options menu, selects a portion of the item to display in Action Bar. Let's look at the source code first, nothing special. The small example is to add in the previous learning example, directly using the inheritance.
public class ActionAreaTestCase2 extends homepresstestcase1{
@Override
public boolean Oncreateoptionsmenu (Menu menu) {
Menuinflater inflater = Getmenuinflater ();
Inflater.inflate (R.menu.bar, menu);
return true;
}
@Override
public boolean onoptionsitemselected (MenuItem item) {
Showinfo ("Select:" + item.gettitle ());
return super.onoptionsitemselected (item);
}
}
The key to see how R.menu.bar XML is set up.
<?xml version= "1.0" encoding= "Utf-8"?>
<menu xmlns:android= "Http://schemas.android.com/apk/res/android" >
<item android:id= "@+id/menu_action_icon1"
Android:title= "Action1"
android:icon= "@drawable/creep001"
android:showasaction= "Ifroom"/><!--compared to the general item, the Showasaction is added to show that in the action bar, in addition to Ifroom, there is always, never, Withtext. You can also use menuitem.setshowasaction (int) in your code to achieve
<item android:id= "@+id/menu_action_icon2"
Android:title= "Action2"
android:icon= "@drawable/creep002"
android:showasaction= "Ifroom"/>
<item android:id= "@+id/menu_action_icon3"
Android:title= "Action3"
android:icon= "@drawable/creep003"
android:showasaction= "Ifroom"/>
... ...
</menu>
If we ask for too many menu items to be displayed in action Bar, then the normal Optionsmenu position is displayed, for example, we set 6 menu items, and the properties are: android:showasaction= "Ifroom", Shown below:
If some properties are not set to showasaction in the menu's XML file, the item is displayed as a regular menu. For example: Normal item is a normal menu item:
If we do not have the icon set, only the title is displayed, the text is shown, and the XML fragment is as follows:
<?xml version= "1.0" encoding= "Utf-8"?>
<menu xmlns:android= "Http://schemas.android.com/apk/res/android" >
<item android:id= "@+id/menu_action_icon1"
Android:title= "Action1"
android:showasaction= "Ifroom"/> <!--No example of icon--
<item android:id= "@+id/menu_action_icon2"
Android:title= "Action2"
android:icon= "@drawable/creep002"
android:showasaction= "Ifroom|withtext"/> <!--show an example of icon and text at the same time-
... ...
</menu>
The example code covered in this blog post can be downloaded in Pro Android Learning: Actionbar Small example.
RELATED Links: My Android development related articles
"Turn" Pro Android Learning Note (49): ActionBar (2): Action icon Area