app:srcCompat does not work for ImageView

谁说我不能喝 提交于 2019-12-10 23:45:37

问题


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

Here's the relevant piece 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's 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 simply change the ImageView to an ImageButton it works. Button also does not work.


回答1:


Maybe you could try changing ImageView to AppCompatImageView. So it becomes:

<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"
/>


来源:https://stackoverflow.com/questions/38003489/appsrccompat-does-not-work-for-imageview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!