Android Studio:底部导航视图-AAPT:错误:''与属性drawable(attr)参考不兼容

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

我已经在我的应用程序中添加了BottomNavigationView之类。

main.xml

<com.google.android.material.bottomnavigation.BottomNavigationView
    android:layout_width="match_parent"
    android:layout_height="56dp"
    app:itemBackground="@drawable/nav_bgcolor"
    app:itemIconSize="50dp"
    app:itemIconTint="@color/nav_item_colors"
    app:itemTextColor="@color/nav_item_colors"
    app:labelVisibilityMode="unlabeled"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:menu="@menu/nav_items">
</com.google.android.material.bottomnavigation.BottomNavigationView>

menu / nav_items.xml

<?xml version="1.0" encoding="utf-8"?>

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

    <item
        android:id="@+id/nav_home"
        android:icon="@drawable/home_white"
        android:title="@string/nav_home" />
    <item
        android:id="@+id/nav_market"
        android:icon="@drawable/market_white"
        android:title="@string/nav_market" />
    <item
        android:id="@+id/nav_news"
        android:icon="@drawable/news_white"
        android:title="@string/nav_news" />
    <item
        android:id="@+id/nav_account"
        android:icon="@drawable/account_white"
        android:title="@string/nav_account" />
</menu>

drawable / nav_bgcolor.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="#FF9800" android:state_checked="true" />
    <item android:drawable="#FFFFFF" android:state_checked="false" />
</selector>

color / nav_item_colors.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="#FFFFFF" android:state_checked="true"/>
    <item android:color="#727272"/>
</selector>

这是android studio中的预览

https://drive.google.com/file/d/1yICxFcTbSxYpILDtxg75Z4x-2Y1UaPM_/view?usp=sharing

它实际上是在显示我想要的设计。

没有任何错误,但是当我运行应用程序时,drawable / nav_bgcolor.xml中存在错误”

C:\Users\[PCNAME]\AndroidStudioProjects\[APPNAME]\app\src\main\res\drawable\nav_bgcolor.xml:3: AAPT: error: '#FF9800' is incompatible with attribute drawable (attr) reference.
C:\Users\[PCNAME]\AndroidStudioProjects\[APPNAME]\app\src\main\res\drawable\nav_bgcolor.xml:4: AAPT: error: '#ffffff' is incompatible with attribute drawable (attr) reference.

在我在main.xml

中添加app:itemBackground =“ @ drawable / nav_bgcolor”后发生了错误

我已经搜索了互联网,但没有得到任何解决方法的运气。

我已经在我的应用程序中添加了BottomNavigationView。 main.xml

android android-layout bottomnavigationview material-components material-components-android
2个回答
0
投票

将drawable / nav_bgcolor.xml中的android:color替换为android:drawable


0
投票

在选择器中,您正在使用

© www.soinside.com 2019 - 2024. All rights reserved.