BottomNavigationBar-change the tab icon color

前端 未结 4 687
太阳男子
太阳男子 2021-01-07 18:48

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?

相关标签:
4条回答
  • 2021-01-07 19:03

    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"
        
    
    0 讨论(0)
  • 2021-01-07 19:13

    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>
    
    0 讨论(0)
  • 2021-01-07 19:19

    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" />
    
    0 讨论(0)
  • 2021-01-07 19:24

    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.

    0 讨论(0)
提交回复
热议问题