VectorDrawable在Lollipop 5.0.1中崩溃我的应用程序

问题描述 投票:2回答:2

我正试图在我的一个片段中使用VectorDrawable选择器。但是,应用程序崩溃显示此错误 -

膨胀矢量时的例外 android.content.res.Resources $ NotFoundException:文件res / drawable / $ ic_lose_weight_icon__0.xml来自颜色状态列表资源ID#0x7f080023

可绘制文件ic_lose_weight_icon.xml包括以下内容 -

<vector android:height="52dp" android:viewportHeight="52.0"
android:viewportWidth="53.0" android:width="52dp"
xmlns:aapt="http://schemas.android.com/aapt" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillType="nonZero"
    android:pathData="M45.23,5.23a6.7,6.7 0,0 0,-4.93 -2.18h-10.22A10.02,10.02 0,0 0,24 1a10.02,10.02 0,0 0,-6.07 2.05L7.71,3.05c-1.87,0 -3.67,0.79 -4.93,2.18A6.72,6.72 0,0 0,1.02 10.3l0.44,5.99c0.03,0.38 0.35,0.66 0.72,0.63a0.68,0.68 0,0 0,0.62 -0.73L2.36,10.2A5.36,5.36 0,0 1,3.76 6.16a5.29,5.29 0,0 1,3.95 -1.75h8.74a10.41,10.41 0,0 0,-2.63 6.94c0,5.71 4.57,10.35 10.18,10.35 5.61,0 10.18,-4.64 10.18,-10.35 0,-2.67 -1,-5.1 -2.63,-6.94h8.74a5.29,5.29 0,0 1,3.95 1.75,5.36 5.36,0 0,1 1.4,4.04l-2.15,29.44c-0.2,2.8 -2.55,5 -5.35,5h-9.67a0.68,0.68 0,0 0,-0.67 0.68c0,0.38 0.3,0.68 0.67,0.68h9.67a6.66,6.66 0,0 0,4.56 -1.8,6.76 6.76,0 0,0 2.13,-4.46l2.15,-29.44a6.72,6.72 0,0 0,-1.75 -5.07zM32.84,11.35c0,4.95 -3.96,8.99 -8.84,8.99 -4.87,0 -8.84,-4.03 -8.84,-8.99 0,-4.96 3.96,-8.99 8.84,-8.99 4.87,0 8.84,4.03 8.84,8.99zM25.09,44.65L10.36,44.65c-2.84,0 -5.22,-2.17 -5.43,-4.94l-1.4,-19.13a0.68,0.68 0,0 0,-0.73 -0.63,0.68 0.68,0 0,0 -0.63,0.72l1.4,19.13a6.62,6.62 0,0 0,2.16 4.41A6.85,6.85 0,0 0,10.36 46h14.72a0.68,0.68 0,0 0,0.68 -0.68,0.68 0.68,0 0,0 -0.68,-0.68z" android:strokeWidth=".5">
    <aapt:attr name="android:fillColor">
        <gradient android:endX="46.98890716996074"
            android:endY="24.500811517238617"
            android:startX="1.9492992758750916"
            android:startY="24.500811517238617" android:type="linear">
            <item android:color="#FF44CFB9" android:offset="0.0"/>
            <item android:color="#FF1EC2C9" android:offset="1.0"/>
        </gradient>
    </aapt:attr>
    <aapt:attr name="android:strokeColor">
        <gradient android:endX="46.98890716996074"
            android:endY="24.500811517238617"
            android:startX="1.9492992758750916"
            android:startY="24.500811517238617" android:type="linear">
            <item android:color="#FF44CFB9" android:offset="0.0"/>
            <item android:color="#FF1EC2C9" android:offset="1.0"/>
        </gradient>
    </aapt:attr>
</path>
<path android:fillType="nonZero" android:pathData="M25.03,10.46a1.82,1.82 0,0 0,-1.27 -0.32L21.47,6.18c-0.2,-0.35 -0.71,-0.71 -1.02,-0.52 -0.32,0.18 -0.32,0.83 -0.12,1.18l2.3,3.98a1.72,1.72 0,0 0,-0.08 0.13c-0.49,0.87 -0.19,2.06 0.69,2.66 0.42,0.29 0.91,0.4 1.38,0.31 0.18,-0.04 0.35,-0.1 0.5,-0.19 0.25,-0.14 0.45,-0.35 0.6,-0.61 0.24,-0.42 0.3,-0.93 0.17,-1.43a2.13,2.13 0,0 0,-0.86 -1.23zM24.89,12.54c-0.11,0.2 -0.3,0.33 -0.52,0.38a0.86,0.86 0,0 1,-0.66 -0.15,1.01 1.01,0 0,1 -0.41,-0.58 0.91,0.91 0,0 1,0.08 -0.68,0.77 0.77,0 0,1 0.52,-0.38 0.86,0.86 0,0 1,0.66 0.15c0.41,0.28 0.56,0.85 0.33,1.26z">
    <aapt:attr name="android:fillColor">
        <gradient android:endX="26.884173301124573"
            android:endY="10.739999532699585"
            android:startX="21.1299991607666"
            android:startY="10.739999532699585" android:type="linear">
            <item android:color="#FF44CFB9" android:offset="0.0"/>
            <item android:color="#FF1EC2C9" android:offset="1.0"/>
        </gradient>
    </aapt:attr>
</path>
<path android:fillColor="#FFF" android:fillType="evenOdd"
    android:pathData="M43,42m-9,0a9,9 0,1 1,18 0a9,9 0,1 1,-18 0" android:strokeWidth="1.5">
    <aapt:attr name="android:strokeColor">
        <gradient android:endX="85.58492" android:endY="75.0"
            android:startX="68.0" android:startY="75.0" android:type="linear">
            <item android:color="#FF44CFB9" android:offset="0.0"/>
            <item android:color="#FF1EC2C9" android:offset="1.0"/>
        </gradient>
    </aapt:attr>
</path>
<path android:fillType="evenOdd" android:pathData="M43.15,45.31L40.36,39.72A0.5,0.5 0,0 1,40.81 39h5.58a0.5,0.5 0,0 1,0.45 0.72l-2.79,5.58a0.5,0.5 0,0 1,-0.89 0z">
    <aapt:attr name="android:fillColor">
        <gradient android:endX="80.75140421012878"
            android:endY="75.29140281677246"
            android:startX="74.29622650146484"
            android:startY="75.29140281677246" android:type="linear">
            <item android:color="#FF44CFB9" android:offset="0.0"/>
            <item android:color="#FF1EC2C9" android:offset="1.0"/>
        </gradient>
    </aapt:attr>
</path>
</vector>

在我的build.gradle文件中,我还添加了这个 -

defaultConfig { 
    vectorDrawables.useSupportLibrary = true
}

随着,

dependencies {
    implementation "com.android.support:appcompatv7:27.1.0"
}

在我使用上面drawable的片段中,我有这个代码 -

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:drawablePadding="8dp"
    android:gravity="center_horizontal"
    android:textAllCaps="false"
    android:textColor="@color/black"
    android:textSize="@dimen/textSize3"
    app:fontName="@string/fnt_roboto_light"
    app:srcCompat="@drawable/ic_lose_weight_icon" />

在我的活动中,我也有这个代码 -

static {
    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}

但每当我在Android 5.0.1 Lollipop中启动我的应用程序时,应用程序会立即崩溃并出现上述错误。

这里的任何帮助将非常感激。谢谢。

android android-support-library android-5.0-lollipop android-vectordrawable
2个回答
0
投票

我有一个类似的问题。好像删除android:fillType =“...”为我解决了它。不确定你的情况下是否需要它的属性。


0
投票

我遇到了同样的问题,将我的gradle版本从3.0.1更新到3.1.0解决了我的问题。

在依赖项块内的项目级gradle文件中使用belove行:

classpath 'com.android.tools.build:gradle:3.1.0'
© www.soinside.com 2019 - 2024. All rights reserved.