Created
February 2, 2018 10:38
-
-
Save rajeefmk/8d57fcd84cc7c857a902c8dcccf36b1b to your computer and use it in GitHub Desktop.
Add counter to any icon
This file contains 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
public class IconCounterUtils { | |
public static void setCounterValue(Context mContext, LayerDrawable icon, int count) { | |
CounterDrawable mCounterDrawable; | |
Drawable reuse = icon.findDrawableByLayerId(R.id.ic_counter); | |
if (reuse != null && reuse instanceof CounterDrawable) { | |
mCounterDrawable = (CounterDrawable) reuse; | |
} else { | |
mCounterDrawable = new CounterDrawable(mContext); | |
} | |
mCounterDrawable.setCounterValue(count); | |
icon.mutate(); | |
icon.setDrawableByLayerId(R.id.ic_counter, mCounterDrawable); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment