app:srcCompat - Vector drawable shows up in design preview, but doesn#39;t show up in app(app:srcCompat - 矢量绘图显示在设计预览中,但不显示在应用程序中)
问题描述
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中.其他项目正确渲染只有矢量drawbles不渲染.
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 - 矢量绘图显示在设计预览中,但不显示在应用程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:app:srcCompat - 矢量绘图显示在设计预览中,但不显示在应用程序中
基础教程推荐
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01