问题描述
我正在使用设计支持库23.2。
我在build.gradle中添加了这些行,因为我的Gradle插件版本为1.5
I'm using the Design Support Library 23.2.I've added these lines in my build.gradle as my Gradle Plugin is version 1.5
defaultConfig {
applicationId "com.abc.xyz"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
generatedDensities = []
}
aaptOptions {
additionalParameters "--no-version-vectors"
}
}
因为它在
但我不能将srcCompat属性用于我的imageview。
But I can't use the srcCompat attribute for my imageview.
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:srcCompat="@drawable/wallpaper"/>
其中@ drawable / wallpaper是矢量资源文件
where @drawable/wallpaper is a vector resource file
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M4,4h7V2H4c-1.1,0 -2,0.9 -2,2v7h2V4zm6,9l-4,5h12l-3,-4 -2.03,2.71L10,13zm7,-4.5c0,-0.83 -0.67,-1.5 -1.5,-1.5S14,7.67 14,8.5s0.67,1.5 1.5,1.5S17,9.33 17,8.5zM20,2h-7v2h7v7h2V4c0,-1.1 -0.9,-2 -2,-2zm0,18h-7v2h7c1.1,0 2,-0.9 2,-2v-7h-2v7zM4,13H2v7c0,1.1 0.9,2 2,2h7v-2H4v-7z"/>
它说
我的Gradle版本是1.5。我怎样才能使用srcCompat?
My Gradle version is 1.5. How can I use srcCompat?
推荐答案
不要
android:srcCompat="@drawable/wallpaper"
app:srcCompat="@drawable/wallpaper"
因为 srcCompat 属性实际上是在 AppCompat 库中定义的。
as it srcCompat attribute is actually defined within AppCompat library.
重要您需要为此添加适当的命名空间。
Important you will need to add appropriate namespace for this.
重要
你可以使用 tools:ignore =MissingPrefix
以避免暂时看到此错误。
you can use tools:ignore="MissingPrefix"
to avoid seeing this error temporarily.
这篇关于不能在android中使用srcCompat for ImageViews的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!