Color selector for vector image not working

I have a vector image (svg converted to xml):

<?xml version="1.0" encoding="utf-8"?> <vector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:better="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" tools:ignore="NewApi" android:viewportWidth="24" better:viewportWidth="24" android:viewportHeight="24" better:viewportHeight="24" android:width="24dp" android:height="24dp"> <path android:pathData="M10.09 15.59l1.41 1.41 5 -5 -5 -5 -1.41 1.41 2.58 2.59 -9.67 0 0 2 9.67 0 -2.58 2.59zM19 3L5 3C3.89 3 3 3.9 3 5l0 4 2 0 0 -4 14 0 0 14 -14 0 0 -4 -2 0 0 4c0 1.1 0.89 2 2 2l14 0c1.1 0 2 -0.9 2 -2L21 5C21 3.9 20.1 3 19 3Z" better:pathData="M10.09 15.59l1.41 1.41 5 -5 -5 -5 -1.41 1.41 2.58 2.59 -9.67 0 0 2 9.67 0 -2.58 2.59zM19 3L5 3C3.89 3 3 3.9 3 5l0 4 2 0 0 -4 14 0 0 14 -14 0 0 -4 -2 0 0 4c0 1.1 0.89 2 2 2l14 0c1.1 0 2 -0.9 2 -2L21 5C21 3.9 20.1 3 19 3Z" android:fillColor="@color/menu_color_selector" better:fillColor="@color/menu_color_selector" /> </vector> 

But the color selector does not work. Is it possible to achieve what I'm trying to do?

+5
source share
1 answer

Try using StateListDrawable with different VectorDrawable for each state you want.

+3
source

Source: https://habr.com/ru/post/1235173/


All Articles