简体   繁体   中英

Cannot set tint programmatically in vector drawable

I'm using SDK 28 to compile this app.

This is the vector xml that I'm using:

<vector android:height="10dp" android:tint="#FFFFFF"
    android:viewportHeight="22" android:viewportWidth="36"
    android:width="14dp"  xmlns:android="http://schemas.android.com/apk/res/android">
    <group android:translateX="13" >
        <path android:fillColor="@android:color/white" android:pathData="M19,15l-1.41,-1.41L13,18.17V2H11v16.17l-4.59,-4.59L5,15l7,7L19,15z"/>
    </group>
</vector>

My question is: how do I change tint programmatically? I have tried solutions I have found on StackOverFlow, but none work.

To set the tint use this code:

ImageViewCompat.setImageTintList(imageView, ColorStateList.valueOf(ContextCompat.getColor(context, R.color.your_color)));

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