android - 在 ImageView 中设置 Vector Drawable 导致应用程序在旧 SDK 中崩溃

标签 android vector crash drawable android-appcompat

我在图像 src 中使用 Vector Drawable 是这样的:

 <ImageView
                android:id="@+id/isSold"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_gravity="center_vertical"
                android:visibility="gone"
                app:srcCompat="@drawable/ic_soldout_24px"
                tools:ignore="MissingPrefix"/>

我还将这些添加到 list 中:

defaultConfig {
        vectorDrawables.useSupportLibrary=true
    }

我使用了compile 'com.android.support:appcompat-v7:23.2.1'

但我的应用程序在旧 sdk 中崩溃并显示消息 Error inflating class ImageView

最佳答案

使用 android.support.v7.widget.AppCompatImageView 而不是 ImageView:

 <android.support.v7.widget.AppCompatImageView
    android:id="@+id/isSold"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center_vertical"
    android:visibility="gone"
    app:srcCompat="@drawable/ic_soldout_24px"
    tools:ignore="MissingPrefix"/>

关于android - 在 ImageView 中设置 Vector Drawable 导致应用程序在旧 SDK 中崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36833309/

相关文章:

android - 测试 Activity 是否返回预期结果

android - 如何在 Android 应用程序及其库之间共享 gradle 依赖项?

C++ 重载 ostream 和 istream 运算符

Android 未捕获且无白屏

安卓填写PDF表格

java - 如何使用套接字编程在Android中测量数据包丢失?

vector - Idris - 自定义相关数据类型的映射函数失败

c++ - 如果使用 remove_if 并且项目是指向对象的指针,如何删除 vector 中的项目?

Python 根本无法工作

python - 如何在不耗尽python内存的情况下遍历大文件?