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="QGRyYXdhYmxlL2luZm9ybWF0aW9u"
/>
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 - 矢量绘图显示在设计预览中,但不显示在应用程序中
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01