androidandroid-bottomnavigationview

BottomNavigationView - How to disable selected icon highlight


I have a bottomnavigation view that sets an icon depending on the state if it's checked or not.

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

    <item
        android:id="@+id/icon_tree"
        android:title="Tree"
        android:icon="@drawable/bottomnav_icon_home">
    </item>

</menu>

bottomnav_icon_home:

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

</selector>

enter image description here

How ever bottomnavigation is automatically highlighting the icon when android:state_checked is true.

enter image description here

How do I completely disable bottomnavigation's icon selection highlight?

I've tried setting app:itemIconTint="@drawable/bottom_navigation_selector" to @null however that doesn't work

<com.google.android.material.bottomnavigation.BottomNavigationView
            android:id="@+id/bottom_navigation"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:menu="@menu/bottom_navigation_menu"
            android:background="@color/colorWhite"
            app:itemTextColor="@drawable/bottom_navigation_selector"
            app:itemIconSize="28dp"
            app:itemIconTint="@drawable/bottom_navigation_selector"
            app:labelVisibilityMode="labeled"/>

bottom_navigation_selector:

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

Solution

  • If i understood you right, android by default sets a tint on your bottom navigation icons on selection and you would like it to be removed right.

    I know how to do that in your java class not xml though.

    You'll need to set setItemIconTintList method of your BottomNavigationView to null. So in wherever you set the layout write code as :

    BottomNavigationView btmNav = findViewById(R.id.bottom_navigation);
    btmNav.setItemIconTintList(null);
    

    Let us know if this works for you.