App: srcCompat does not work for ImageView

I am adding vector support for a library project and using app:srcCompat to reference a vector resource. The only view that seems to work is ImageButton, and I'm not sure why.

Here is the corresponding snippet of my build.gradle

 android { defaultConfig { vectorDrawables.useSupportLibrary = true } } dependencies { testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:24.0.0' compile 'com.android.support:support-vector-drawable:24.0.0' compile 'com.android.support:animated-vector-drawable:24.0.0' compile 'uk.co.chrisjenx:calligraphy:2.2.0' } 

Here is my layout file:

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center_horizontal" > <ImageView android:id="@+id/iconActive" style="@style/Widget.MyCompany.Button.Icon" app:srcCompat="@drawable/activities" android:layout_marginTop="16dp" android:tint="@color/white" /> </LinearLayout> 

If I just changed ImageView to ImageButton, this will work. The button also does not work.

+2
android vector-graphics android-support-library
source share
1 answer

Perhaps you could try changing ImageView to AppCompatImageView . So it is done:

 <android.support.v7.widget.AppCompatImageView android:id="@+id/iconActive" style="@style/Widget.MyCompany.Button.Icon" app:srcCompat="@drawable/activities" android:layout_marginTop="16dp" android:tint="@color/white" /> 
+3
source share

All Articles