Change fill color on vector asset in Android Studio

后端 未结 12 1965
盖世英雄少女心
盖世英雄少女心 2020-12-02 04:09

Android Studio now supports vector assets on 21+ and will generate pngs for lower versions at compile time. I have a vector asset (from the Material Icons) that I want to c

12条回答
  •  执念已碎
    2020-12-02 04:54

    Update: AppCompat support

    Other answers suspecting if android:tint will work on only 21+ devices only, AppCompat(v23.2.0 and above) now provides a backward compatible handling of tint attribute.

    So, the course of action would be to use AppCompatImageView and app:srcCompat(in AppCompat namespace) instead of android:src(Android namespace).

    Here is an example(AndroidX: This is androidx.appcompat.widget.AppCompatImageView ;)):

    
    

    And don't forget to enable vector drawable support in gradle:

    vectorDrawables.useSupportLibrary = true 
    

提交回复
热议问题