Skip to content

Instantly share code, notes, and snippets.

@rajeefmk
Created February 2, 2018 10:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rajeefmk/8d57fcd84cc7c857a902c8dcccf36b1b to your computer and use it in GitHub Desktop.
Save rajeefmk/8d57fcd84cc7c857a902c8dcccf36b1b to your computer and use it in GitHub Desktop.
Add counter to any icon
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