How to change bottom navigation icons on selection and unselection This was my previous code
bottomBar.getBar().setBackgroundColor(getResources().getColor(R.color.bottom_tabs));
bottomBar.setActiveTabColor("#FFFFFE");
CodePudding user response:
First you have to make drawable selectable in your drawable folder
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:drawable="@drawable/selected_icon"/>
<item android:state_selected="false" android:drawable="@drawable/unselected_icon" />
<item android:drawable="@drawable/unselected_icon" />
</selector>
In the bottom navigation menu place this selectable drawable as icon
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@ id/itemId"
android:icon="@drawable/drawable_selectable_name"
android:title="@string/title"/>
</menu>
In activity or fragment where you have used bottom navigation use the following line
bottomNavigationView.itemIconTintList = null