StickerView
StickerView copied to clipboard
Cannot set two different colors for same drawable
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.
add following code to DrawableSticker
@NonNull public Sticker setStickerColor(@ColorInt int color, PorterDuff.Mode mode) { drawable.setColorFilter(color, mode); drawable = drawable.mutate(); return this; }