Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
446 views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...