-1

I want to change the background color of selected item in navigation view.

I have tried with selector color file and also drawable but nothing is working.. when i run all the time exception at itemBackground attribute..

background_color_tab.xml

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

Bottom Navigation line no 49 is (app:itemBackground)

<android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_alignParentBottom="true"
        android:layout_width="match_parent"
        android:layout_height="70dp"
        app:menu="@menu/bottom"
        app:itemIconTint="@color/selector_bottom_navigation"
        app:itemTextColor="@color/selector_bottom_navigation"
        app:itemBackground="@color/background_color_tab"
        android:textAlignment="center"
        app:labelVisibilityMode="labeled"
        android:background="@android:color/white"
        app:itemIconSize="@dimen/icon_size"
        app:elevation="5dp">
    </android.support.design.widget.BottomNavigationView>

ERROR

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ccms/com.example.ccms.MainActivity}: android.view.InflateException: Binary XML file line #49: Binary XML file line #49: Error inflating class android.support.design.widget.BottomNavigationView

Vipul Prajapati
  • 1,183
  • 9
  • 11

1 Answers1

1

you can not set color resource in app:itemBackground you must have to set drawable resource in this property

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/blue" android:state_checked="true" />
    <item android:drawable="@android:color/black" android:state_checked="false" />
</selector>
Priyanka
  • 3,369
  • 1
  • 10
  • 33