I\'ve integrated Bottom Bar Navigation bar on my app. But when I swipe, tab\'s color doesn\'t change. It\'s weird cause I have selector file. Any idea to solve this problem?
I was confused about whole process despite reading all the answers, so here is how I resolved it step by step so beginners can understand it properly
Let's say you created MainActivity
with bottom navigation so
in your drawable
folder create bottom_navigation_selector.xml
<?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/yourSelectedColor" />
<item android:color="@color/defaultColor" />
</selector>
then go to the activity_main.xml
layout and add this line in BottomNavigationView
app:itemIconTint="@drawable/bottom_navigation_selector"
If you also want to change text color accordingly then you need to add this line aswell
app:itemTextColor="@drawable/bottom_navigation_selector"
Change to app:itemIconTint="@drawable/selector"
Also change your selector.xml
to this:
<?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/beyaz" />
<item android:color="@color/colorPrimaryDark" />
</selector>
You have to set selector as itemIconTint of your BottomNavigationView. Something like
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
app:itemBackground="@color/colorPrimary"
app:itemIconTint="@drawable/selector"
app:itemTextColor="@color/beyaz"
app:menu="@menu/bottombar_menu" />
You need to add this in your BottomNavigationView
android:theme="@style/Base.ThemeOverlay.AppCompat.Dark.ActionBar"
It will help you to change the color of icon.