问题描述
我有一个 TextView
使用可绘制的矢量作为背景。矢量 drawable 的 path
包含一个 strokeColor
和 strokeWidth
,因此它基本上只是自定义形状的轮廓。它没有给出 fillColor
;但是,我想以编程方式为颜色设置动画。
我试过应用颜色过滤器,但它没有考虑路径,所以它只是在整个形状上绘制一个框。我尝试过其他 PorterDuff
模式,但它们似乎都删除了原始 drawable 的笔划。可能有一个适当的模式,但它似乎设计不佳,而不是提供用于修改 stroke
、strokeWeight
和 fillColor
的默认函数。
VectorDrawable drawable = (VectorDrawable) textView.getBackground();
drawable.setColorFilter(Color.argb(255,v,v),PorterDuff.Mode.SRC_ATOP);
textView.setBackground(drawable);
我发现 GradientDrawable
可以做我需要的一切,但我无法用它定义自定义形状。它保持正确的笔触并填充区域。
GradientDrawable gd = new GradientDrawable();
gd.setColor(Color.argb(255,v));
gd.setstroke(2,Color.WHITE);
textView.setBackground(gd);
如果 VectorDrawable
有这些功能就很简单了。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)