BottomNavigationView菜单中的矢量可绘制对象导致错误

时间:2018-09-01 17:59:26

标签: android bottomnavigationview android-vectordrawable

我正尝试将矢量可绘制对象用作BottomNavigationView的图标,如下所示:

<menu
    xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:id="@+id/navigation_incoming"
        android:icon="@drawable/incoming_background"
        android:title="Incoming"/>

    <item
        android:id="@+id/navigation_outgoing"
        android:icon="@drawable/outgoing_background"
        android:title="Outgoing"/>

    <item
        android:id="@+id/navigation_important"
        android:icon="@drawable/favorite_background"
        android:title="Favourite"/>
    <item
        android:id="@+id/navigation_settings"
        android:icon="@drawable/settings_background"
        android:title="Settings"/>

</menu>

我的可绘制对象就像:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_selected="true" android:drawable="@drawable/ic_incoming_active"/>
    <item android:drawable="@drawable/ic_incoming_inactive"/>
</selector>

@drawable/ic_incoming_active@drawable/ic_incoming_inactive都是矢量可绘制对象。

我也在使用vectorDrawables.useSupportLibrary = true

implementation "com.android.support:support-vector-drawable:27.1.1"

但是我得到了

Caused by: android.content.res.Resources$NotFoundException: File res/drawable/ic_incoming_active.xml from drawable resource

1 个答案:

答案 0 :(得分:0)

该错误表示找不到可绘制的ic_incoming_active.xml
在大多数情况下,原因是您将此可绘制对象存储在drawable-v21之类的文件夹中,而不是res/drawable中。