Android Actionbar Simple to use

Source: Internet
Author: User

ActionBar appears after API 11 in Android 3.0, replacing the title bar before 3.0

Actionbar is divided into four districts

A: Icon | | B: Title | | C: Content Switching | | D: Menu

Common methods

Activity.getactionbar ()//Get Actionbar object in activity

A:

Actionbar.setdisplayhomeasupenabled (Boolean)//Set whether a region can be clicked

Actionbar.setdisplayshowhomeenabled (Boolean)//sets whether a area icon is displayed

Event Listener Activity Rewrite Onmenuitemselected method, Android. R.id.home for zone button ID

@Override  Public boolean onmenuitemselected (int  Featureid, MenuItem item) {    if// TODO        Toast.maketext (This, "Home", Toast.length_short). Show ();     return Super . onmenuitemselected (Featureid, item);}

B:

Actionbar.settitle (charsequence)//Settings area display content

Actionbar.setdisplayshowtitleenabled (FALSE); Sets whether the area is displayed

C:

Actionbar.setnavigationmode (int)//Set style for this area

Actionbar.navigation_mode_standard//default


Actionbar.navigation_mode_tabs//tab

Actionbar.setnavigationmode (Actionbar.navigation_mode_tabs); Actionbar.tablistener Tablistener=NewActionbar.tablistener () {@Override Public voidontabunselected (Tab tab, fragmenttransaction ft) {} @Override Public voidontabselected (Tab tab, fragmenttransaction ft) {} @Override Public voidontabreselected (Tab tab, fragmenttransaction ft) {}};actionbar.addtab (Actionbar.newtab (). SetText ("Tab_01"). Settablistener (Tablistener)), Actionbar.addtab (Actionbar.newtab (). SetText ("Tab_02"). Settablistener (Tablistener)), Actionbar.addtab (Actionbar.newtab (). SetText ("Tab_03"). Settablistener (Tablistener));//If you don't add a listener, you'll get an error

Actionbar.navigation_mode_list//LIST display

Actionbar.setnavigationmode (actionbar.navigation_mode_list); string[] Lists= {"List_01", "list_02", "list_03" }; Arrayadapter<String> ListAdapter =NewArrayadapter<string> ( This, Android. R.layout.simple_spinner_item, lists); Actionbar.onnavigationlistener Navlistener=NewActionbar.onnavigationlistener () {@Override Public BooleanOnnavigationitemselected (intARG0,Longarg1) {        return false; }};actionbar.setlistnavigationcallbacks (ListAdapter, navlistener);

D:

About the D menu area is equivalent to rewrite 3.0 before the menu, the screen will not show the display of three points, click will expand

Item generation and event snooping, overriding the following methods in activity

@Override Public BooleanOncreateoptionsmenu (Menu menu) {Super. Getmenuinflater (). Inflate (R.menu.main, menu);//Fill Menu    return true;} @Override Public Booleanonoptionsitemselected (MenuItem item) {intID =Item.getitemid (); //TODO based on ID judgment processing    return Super. onoptionsitemselected (item);}

Android Actionbar Simple to use

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.