问题描述
每当我使用Android Studio的Vector Assets创建带有图标的ImageView时,在app:srcCompat="@drawable/ic_play"
Whenever I create an ImageView with icon added using Android Studio's Vector Assets, I'm getting an error at the line app:srcCompat="@drawable/ic_play"
当我用android:src
更改app:srcCompat
时,错误消失了,但是图标看起来像是像素化的.
When I change the app:srcCompat
with android:src
, the error is gone but the icon looks pixelated.
app:srcCompat="@drawable/ic_play"
和
android:src="@drawable/ic_play"
推荐答案
app:srcCompat
注意
截至 Android支持库23.3.0 >, 支持向量可绘制对象 只能通过 app:srcCompat
加载.
As of Android Support Library 23.3.0, support vector drawables can only be loaded via app:srcCompat
.
您需要将 vectorDrawables.useSupportLibrary = true 添加到您的build.gradle
文件
you need to add vectorDrawables.useSupportLibrary = true to your build.gradle
file
// Gradle Plugin 2.0+
android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}
android:src
这篇关于Android布局XML中的app:srcCompat和android:src之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!