srcCompact 属性无法使用视图样式

srcCompact attribute not working using view style

我正在尝试使用样式中的属性 srcCompat:

<item name="app:srcCompat">@drawable/ic_work</item>

Android Studio 对此只字未提,但在编译时出现此错误:

error: style attribute 'app:attr/srcCompat' not found. Message{kind=ERROR, text=error: style attribute 'app:attr/srcCompat' not found., sources=[D:...\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:2888], original message=, tool name=Optional.of(AAPT)}

您需要将以下代码添加到 gradle vectorDrawables.useSupportLibrary = true

android {  
    defaultConfig {  
        vectorDrawables.useSupportLibrary = true 
    }  
}

您似乎想在样式中使用该属性。因此你不需要 app-prefix:

<item name="srcCompat">@drawable/ic_work</item>

您需要使用 AppCompatImageView 才能使用 srcCompat 而不是 ImageView。

<android.support.v7.widget.AppCompatImageView
                    android:id="@+id/imageView"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />