I use the following line to change the color of a VectorDrawable:
mydrawable.getBackground().setColorFilter(color, PorterDuff.Mode.SRC_ATOP)
This works nice, though it is now deprecated. The documentation suggests that I use:
mydrawable.getBackground().setColorFilter(new BlendModeColorFilter(color, PorterDuff.Mode.SRC_ATOP))
Though, BlendModeColorFilter
is only available on API29. After examining the source of the deprecated method, I have realized that it calls:
new PorterDuffColorFilter()
So, I went ahead and used:
mydrawable.getBackground().setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP))
The coloring worked. Is this the right replacement for the deprecated method or I must use BlendModeColorFilter on API29?
Thank you.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…