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