简体   繁体   中英

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?

Yes you can with Support Library.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM