StickerView icon indicating copy to clipboard operation
StickerView copied to clipboard

Cannot set two different colors for same drawable

Open KamdarRushabh opened this issue 7 years ago • 1 comments

Hi,

I am using this code to add sticker from drawables: `public void addStickerView(String string) { Drawable drawable = ContextCompat.getDrawable(context, getResources().getIdentifier(string, "drawable", getPackageName())); stickerView.addSticker(new DrawableSticker(drawable)); } public void setColor(int color) { if(currentSticker instanceof TextSticker){ ((TextSticker) currentSticker).setTextColor(color); } else { currentSticker.getDrawable().setColorFilter(color, PorterDuff.Mode.MULTIPLY); } stickerView.invalidate(); }

public void somefunction(){ addStickerView("image"); // Setting currentSticker as above added sticker setColor(Color.RED); addStickerView("image"); } `

Here I am adding "R.drawable.image" two times, but as per code only first sticker should have red color and other should have default color. But on running, both images have RED color.

Please tell me how to fix it.

KamdarRushabh avatar May 24 '17 13:05 KamdarRushabh

add following code to DrawableSticker

@NonNull public Sticker setStickerColor(@ColorInt int color, PorterDuff.Mode mode) { drawable.setColorFilter(color, mode); drawable = drawable.mutate(); return this; }

rahul107 avatar Aug 13 '17 09:08 rahul107