Vedant
Vedant

Reputation: 468

Selected Item on BottomNavigationView is not visible

I have a BottonNavigationView. Whichever Item is selcted gets hidden. I also added the visible tag, but it still remains the same. The code for navigation is :

<?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/navigation_tasks"
        android:enabled="true"
        android:icon="@drawable/tasks"
        android:title="@string/tasks"
        android:visible="true" />

    <item
        android:id="@+id/navigation_dashboard"
        android:enabled="true"
        android:icon="@drawable/ic_dashboard_black_24dp"
        android:title="@string/title_dashboard"
        android:visible="true" />

    <item
        android:id="@+id/navigation_notifications"
        android:enabled="true"
        android:icon="@drawable/ic_notifications_black_24dp"
        android:title="@string/title_notifications"
        android:visible="true" />

</menu>

The layout file contains :

<android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:alwaysDrawnWithCache="true"
        android:background="?android:attr/windowBackground"
        android:clickable="true"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:menu="@menu/navigation" />

Here are the screenshots :

enter image description here enter image description here

Upvotes: 4

Views: 1913

Answers (1)

Abhishek Singh
Abhishek Singh

Reputation: 9188

Your BottomNavigationView color is white and selected item color is also white try changing background of BottomNavigationView by app:itemBackground="@color/colorPrimary"

OR

If you want white background BottomNavigationView then change color of items based on state like this-

Create a drawable name item_color_state.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <!--Selected Item Color--> 
    <item android:color="@color/blue" android:state_checked="true" />

    <!--Unselected Item Color--> 
    <item android:color="@color/gray" android:state_checked="false"/>
</selector>

In your BottomNavigationView add this

<android.support.design.widget.BottomNavigationView
    ...
    app:itemIconTint="@drawable/item_color_state"
    app:itemTextColor="@drawable/item_color_state"
    ...
    />

Note- return true in onNavigationItemSelected

Upvotes: 4

Related Questions