Is it possible to tint vector drawable with ColorStateList

时间:2016-08-31 12:33:10

标签: android svg android-support-library android-vectordrawable

Now I have something like

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/bg_button_selected" android:state_selected="true"/>
    <item android:drawable="@drawable/bg_button_pressed" android:state_pressed="true"/>
    <item android:drawable="@drawable/bg_button_normal"/>
</selector>

Where bg_button_selected, bg_button_pressed, bg_button_normal are very same PNG's, the only difference is color.

Can I replace set of PNG's with single SVG and set tint to it somehow like this?

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="@color/bg_color_selected" android:state_selected="true"/>
    <item android:color="@color/bg_color_pressed" android:state_pressed="true"/>
    <item android:color="@color/bg_color_normal"/>
</selector>

And is it possible for pre Lollipop devices?

1 个答案:

答案 0 :(得分:1)

是的,您可以使用支持库。

您可以使用ViewCompat.setBackgroundTintList(View, ColorStateList)