I have chat bubbles which I want to tint in some situations:
Drawable bubbleDrawable = ContextCompat.getDrawable(context, R.drawable.bg_chat_bubble);
if (tint) {
bubbleDrawable = DrawableCompat.wrap(bubbleDrawable);
DrawableCompat.setTint(bubbleDrawable, bubbleTint);
}
The problem is that once once that R.drawable.bg_chat_bubble
(it is a 9-patch) was tinted then all calls to ContextCompat.getDrawable(context, R.drawable.bg_chat_bubble)
returns the tinted image instead of the orignal. Even when I close a chat and open completely different chat, the bubbles there have the previous tint. Only killing the app helps to restore the correct color. Until the first tint...
Even directly setting the bubbleDrawable = ContextCompat.getDrawable(context, R.drawable.bg_chat_bubble)
inside the tint branch after calling setTint
gives a tinted image instead of the original.
I also tried getResources().getDrawable(R.drawable.bg_chat_bubble)
but the result is the same. So once I want to use a tint for any drawable resrouce I must always set a tint for that resource otherwise I get unpredictable results.
This is happening on Android 5.1 (probably also others) and with appcompat-v7:23.2.+
and appcompat-v7:23.1.+
. Is this a know bug or I am doing something wrong?