I have a TextView
that utilizes a vector drawable for the background. The vector drawable's path
contains a strokeColor
and strokeWidth
, so it's basically just an outline of a custom shape. It has no given fillColor
; however, I want to animate the color programmatically.
I've tried applying a Color filter, but it doesn't take the path into account, so it just draws a box over the entire shape. I've tried other PorterDuff
modes, but they all seems to remove the stroke of the original drawable. There might be a proper mode, but it seems like poor design rather than supplying default functions for modifying the stroke
, strokeWeight
, and fillColor
.
VectorDrawable drawable = (VectorDrawable) textView.getBackground();
drawable.setColorFilter(Color.argb(255, v, v, v), PorterDuff.Mode.SRC_ATOP);
textView.setBackground(drawable);
I've found that GradientDrawable
can do everything I need, but I haven't been able to define a custom shape with it. It keeps the proper stroke and fills the area.
GradientDrawable gd = new GradientDrawable();
gd.setColor(Color.argb(255, v, v, v));
gd.setStroke(2, Color.WHITE);
textView.setBackground(gd);
It would be simple if VectorDrawable
had these functions.