解决方法
整个矢量的颜色可以使用setTint来改变.
- <ImageView
- android:id="@+id/myImageView"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:tint="@color/my_nice_color"
- android:src="@drawable/ic_my_drawable"
- android:scaleType="fitCenter" />
然后改变你的形象的颜色:
- DrawableCompat.setTint(myImageView.getDrawable(),ContextCompat.getColor(context,R.color.another_nice_color));
注意:如果矢量drawable设置为imageView作为背景,myImageView.getDrawable()将给出nullpointerexception.