Reputation: 2861
I'm trying to create custom shortcut icons that, via Intents, call an activity inside my app. The problem is that I want to create them either by modifying one of my app's drawables or (preferably) one of my layouts.
For the drawables, I have tried this
Drawable iconDrawable = getResources().getDrawable(iconResource);
iconDrawable.mutate();
iconDrawable.setColorFilter(0xff00ff00, PorterDuff.Mode.SRC_ATOP);
BitmapDrawable bd = (BitmapDrawable) iconDrawable;
bd.mutate();
bd.setColorFilter(0xff00ff00, PorterDuff.Mode.SRC_ATOP);
putShortCutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, bd.getBitmap());
but it doesn't work, the drawable is shown as-is, without modifying its color.
And as for creating the icon from a custom layout, which is what I really want to do... I simply don't know where to begin.
Could anyone please tell me how to do it or at least point me in the right direction?
Thanks!
Upvotes: 0
Views: 2610
Reputation: 2861
Okay, I found the answer by studying the AnyCut source code, and the "trick" is to use a Canvas:
(more precisely, the generatePhoneNumberIcon function).
Upvotes: 1