Last active
September 18, 2017 05:08
-
-
Save rajsuvariya/64cbc6501c1d14afc3d9ebc92167da0f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public boolean onPrepareOptionsMenu(Menu menu) { | |
setCount(this, "9"); | |
} | |
public void setCount(Context context, String count) { | |
MenuItem menuItem = defaultMenu.findItem(R.id.ic_group); | |
LayerDrawable icon = (LayerDrawable) menuItem.getIcon(); | |
CountDrawable badge; | |
// Reuse drawable if possible | |
Drawable reuse = icon.findDrawableByLayerId(R.id.ic_group_count); | |
if (reuse != null && reuse instanceof CountDrawable) { | |
badge = (CountDrawable) reuse; | |
} else { | |
badge = new CountDrawable(context); | |
} | |
badge.setCount(count); | |
icon.mutate(); | |
icon.setDrawableByLayerId(R.id.ic_group_count, badge); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment