0

I am creating an app in which I created a bottom navigation bar. Now what I want is to set separate colors for selected/unselected state of nav bar items. So I created an xml file and set it for item tint and text color for navigation bar as shown:

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

and in main menu adding navigation bar as:

<android.support.design.widget.BottomNavigationView
        android:id="@+id/mainNav"
        android:layout_width="match_parent"
        android:layout_height="56dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:background="@android:color/white"
        android:elevation="8dp"
        app:itemIconTint="@color/nav_bar_item_state"
        app:itemTextColor="@color/nav_bar_item_state"
        app:menu="@menu/nav_items"></android.support.design.widget.BottomNavigationView>

I got this solution from this link:

Selected tab's color in Bottom Navigation View

But when I run the app it crashes with error "unable to inflate navigation bar". What am I doing wrong? Any help would be appreciated.

Update: I tried the same thing by creating selector file in drawable file but unfortunately it also doesn't work.

kinza
  • 535
  • 11
  • 31
  • Hey , follow the link given you will get the idea ,HAPPY COADING https://www.androidhive.info/2017/12/android-working-with-bottom-navigation/ – niya panchal May 18 '18 at 11:08

1 Answers1

0

Try this:-
Set item.setCheckable(true) inside onNavigationItemSelected()

public boolean onNavigationItemSelected(MenuItem item) {

    switch (item.getItemId()) {
        case R.id.navigation_home:
            item.setCheckable(true);
            mTextMessage.setText(R.string.title_home);
            return true;
    }
    return false;
}
Arshad
  • 1,262
  • 16
  • 25
Mr. Roshan
  • 1,777
  • 13
  • 33