app:srcCompat - Vector drawable出现在设计预览中,但不会显示在应用程序中 [英] app:srcCompat - Vector drawable shows up in design preview, but doesn't show up in app
问题描述
drawable / information.xml
drawable/information.xml
<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="M13,9H11V7H13M13,17H11V11H13M12,2A10,10 0,0 0,2 12A10,10 0,0 0,12 22A10,10 0,0 0,22 12A10,10 0,0 0,12 2Z"/>
</vector>
LayoutofCardView.xml
LayoutofCardView.xml
<ImageView
android:layout_width="24dp"
android:background="#f00"
android:layout_height="24dp"
android:id="@+id/informationImageView"
app:srcCompat="@drawable/information"
tools:src="@drawable/information"
/>
build.gradle
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.company"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
generatedDensities = []
}
aaptOptions {
additionalParameters "--no-version-vectors"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE.txt'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:cardview-v7:23.2.1'
compile 'com.android.support:recyclerview-v7:23.2.1'
compile 'com.android.support:support-v4:23.2.1'
}
图像在android studio的设计面板中正确显示。但是当我运行应用程序时,图像不会显示。该图像位于cardView中,位于recyclerviewfragment中。其他项目正确呈现只有矢量图形不呈现。
The image shows up correctly in the design pane of android studio. But when I run the app, the image doesn't show up. The image is in cardView, which is in recyclerviewfragment. other items render correctly only vector drawbles don't render.
此外,Lint错误显示在布局文件中
Also, Lint error shows up in the layout file
unexpected namespace prefix "app" found for tag ImageView app:srcCompat
推荐答案
将此行 vectorDrawables.useSupportLibrary = true
作为defaultConfig语句的一部分插入build.graddle文件中。我使用了这里它的工作原理。认为您必须注意Gradle 2.0+和Gradle 1.5的配置看起来不同。
Insert this line vectorDrawables.useSupportLibrary = true
into your build.graddle file as part of the defaultConfig statement. I've used the descriptions that are provided here and it works. Think you have to be aware that config looks different for Gradle 2.0+ and Gradle 1.5.
无论您使用的Gradle版本如何,您都必须确保活动必须扩展 AppCompatActivity 以提供矢量支持。
Regardless of the Gradle version you're using, you have to ensure that that your activity has to extend AppCompatActivity to provide vector support.
这篇关于app:srcCompat - Vector drawable出现在设计预览中,但不会显示在应用程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!