Android Actionbarsherlock Usage Instructions

Source: Internet
Author: User

Source code Address: Https://github.com/JakeWharton/ActionBarSherlock

1. Add a project Dependency package

2. Modify the theme in Androidmanifest.xml (or inherit the parent style of the theme)

Android:theme= "@style/theme.sherlock.light"

3. The custom activity must inherit the Sherlockactivity class

4. Rewrite the Oncreateoptionsmenu and onoptionsitemselected methods.

@Override      Public Boolean Oncreateoptionsmenu (Menu menu) {                getsupportmenuinflater (). Inflate (R.menu.main_menu, menu);         return Super . Oncreateoptionsmenu (menu);    }
@Override      Public Boolean onoptionsitemselected (MenuItem item) {        switch(Item.getitemid ()) {        case Android. R.id.home:// Click the app icon            toast.maketext(This, "home as Up", Toast.length_long ). Show ();              Break ;        }         return Super . onoptionsitemselected (item);    }

The first method sets menu, the second method sets the menu's Click event

Complete these four steps to use the framework

Let's talk about some small operations in the framework

1. Replace the icon in the upper left corner to use two methods

Getsupportactionbar (). SetIcon (R.drawable.e_1);
Getsupportactionbar (). Setlogo (R.drawable.e_1);

2. Setting the title

Getsupportactionbar (). Settitle ("Product Details");

3. Setting the background of the Actionbar

drawable drawable = getresources (). getdrawable (r.drawable.e_1);        Getsupportactionbar (). setbackgrounddrawable (drawable);

4. Two ways to set the icon in the upper left corner can be clicked

Getsupportactionbar (). setdisplayhomeasupenabled (true);
Getsupportactionbar (). sethomebuttonenabled (true);

5. Click on the icon in the upper left corner of the monitor

@Override      Public Boolean onoptionsitemselected (MenuItem item) {        switch(Item.getitemid ()) {        case Android. R.id.home:// Click the app icon            toast.maketext(This, "home as Up", Toast.length_long ). Show ();              Break ;        }         return Super . onoptionsitemselected (item);    }

6. Set whether the caption is available, true is available and the caption is displayed, False is unavailable, the caption is hidden

Getsupportactionbar (). setdisplayshowtitleenabled (true);

7. Non-completion of the adjournment

Android Actionbarsherlock Usage Instructions

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.