ActionItemBadge: displays the badge number prompt on the actionbar.

Source: Internet
Author: User
Introduction: a library that allows you to display digit prompts on the actionbar (this effect is called badge ). The implementation principle is to use the menu resource file attribute actionLayout to run the effect: Instructions for use:

Create a menu. xml according to the normal method, and addActionLayoutTo always display this menu item, addShowAsAction ="Always".

<Itemandroid: id = "@ + id/item_samplebadge" android: actionLayout = "@ layout/menu_badge" android: showAsAction = "always" android: title = "@ string/sample_1"/>

 

Activity

Override onCreateOptionsMenu

 

@ Overridepublic boolean onCreateOptionsMenu (Menu menu) {// Inflate the menu; this adds items to the action bar if it is present. getMenuInflater (). inflate (R. menu. main, menu); // you can add some logic (hide it if the count = 0) if (badgeCount> 0) {ActionItemBadge. update (this, menu. findItem (R. id. item_samplebadge), Iconify. iconValue. fa_android, ActionItemBadge. badgeStyle. DARKGREY, badgeCount);} else {ActionItemBadge. hide (menu. findItem (R. id. item_samplebadge);} // If you want to add your ActionItem programmatically you can do this too. you do the following: new ActionItemBadge. add (). act (this ). menu (menu ). title (R. string. sample_2 ). itemDetails (0, SAMPLE2_ID, 1 ). showAsAction (MenuItem. SHOW_AS_ACTION_ALWAYS ). build (ActionItemBadge. badgeStyle. BLUE_LARGE, 1); return true ;}

If you want to re-update the number of badge entries after you click the menu itemOnOptionsItemSelectedCallingInvalidateOptionsMenuMethod:

@ Overridepublic boolean onOptionsItemSelected (MenuItem item) {int id = item. getItemId (); if (id = R. id. item_samplebadge) {Toast. makeText (this, R. string. sample_3, Toast. LENGTH_SHORT ). show (); badgeCount --; invalidateOptionsMenu (); return true;} else if (id = SAMPLE2_ID) {Toast. makeText (this, R. string. sample_4, Toast. LENGTH_SHORT ). show ();} return super. onOptionsItemSelected (item );}

 

Source code download: http://jcodecraeer.com/a/opensource/2014/1105/1910.html

ActionItemBadge: displays the badge number prompt on the actionbar.

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.