wuapnjie / StickerView

[No more support] A view which can add sticker and zoom,drag,delete it
MIT License
1.27k stars 311 forks source link

Cannot set two different colors for same drawable #37

Open KamdarRushabh opened 7 years ago

KamdarRushabh commented 7 years ago

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.

rahul107 commented 7 years ago

add following code to DrawableSticker

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