Simple use of Android ActionBar and androidactionbar

Source: Internet
Author: User

Simple use of Android ActionBar and androidactionbar

ActionBar is actually Menu

1. Compile the menu interface in res/menu


<Menu xmlns: android = "http://schemas.android.com/apk/res/android">


<Item
Android: id = "@ + id/menu01"
Android: icon = "@ android: drawable/ic_menu_rotate"
Android: orderInCategory = "100"
Android: showAsAction = "always"
Android: title = "unread message"/>
<Item
Android: id = "@ + id/menu02"
Android: icon = "@ android: drawable/ic_menu_more"
Android: orderInCategory = "101"
Android: title = "more"
Android: showAsAction = "ifRoom | withText"/>
<Item
Android: id = "@ + id/menu03"
Android: icon = "@ android: drawable/ic_menu_add"
Android: orderInCategory = "102"
Android: showAsAction = "ifRoom | withText"
Android: title = "system settings"/>
<Item
Android: id = "@ + id/menu04"
Android: icon = "@ android: drawable/ic_menu_delete"
Android: orderInCategory = "103"
Android: showAsAction = "ifRoom | withText"
Android: title = "Advanced Settings"/>
<Item
Android: id = "@ + id/menu05"
Android: icon = "@ android: drawable/ic_menu_help"
Android: orderInCategory = "104"
Android: showAsAction = "ifRoom | withText"
Android: title = "help"/>


</Menu>

2. Get ActionBar in Activity


AB = getActionBar (); // get actionBar
AB. setTitle ("");

AB. setDisplayHomeAsUpEnabled (true); // return to the previous interface

3. Reload onCreateOptionsMenu () to map menu. xml to menu, and reload onOptionsItemSelected () to operate the menu.


Code sample http://download.csdn.net/detail/wangdianyong/8541061

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.