Search code examples
androidsvgandroid-support-libraryandroid-vectordrawable

Is it possible to tint vector drawable with ColorStateList


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?


Solution

  • Yes you can with Support Library.

    You can use ViewCompat.setBackgroundTintList(View, ColorStateList).