How to change inactive color in bottom navigation?

I can’t change the inactive color in my bottom navigation

http://i.stack.imgur.com/uNjUu.jpg

and this is my xml

<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
    android:id="@+id/home_item"
    android:icon="@drawable/ic_home"
    android:color="#FFFFFF"
    android:tint="#FFFFFF"
    android:backgroundTint="#FFFFFF"
    android:title="Home"
    />
<item
    android:id="@+id/setting_item"
    android:icon="@drawable/ic_setting"
    android:color="#FFFFFF"
    android:tint="#FFFFFF"
    android:backgroundTint="#FFFFFF"
    android:title="Setting"
    />

and this is my java

bottomBar.getBar().setBackgroundColor(getResources().getColor(R.color.bottom_tabs));
bottomBar.setActiveTabColor("#FFFFFE");

Can anybody help?

+4
source share
1 answer

If you use BottomNavigationView, the solution may be simple. You just need to create the selector as a ColorStateList , and then assign the selector to the "itemIconTint" attribute in the BottomNavigationView.

For instance:

bottom_nav_icon_color_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="@android:color/white" />
    <item android:state_pressed="true" android:state_enabled="true" android:color="@android:color/white" />
    <item android:color="@color/InactiveBottomNavIconColor" />

BotttomNavigationview.xml

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/bottomNavMainMenu"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        app:itemBackground="@color/BottomNavBarColor"
        app:itemIconTint="@color/bottom_nav_icon_color_selector"
        app:itemTextColor="@color/bottom_nav_icon_color_selector"
        app:menu="@menu/bottom_navigation_menu" />
+13
source

Source: https://habr.com/ru/post/1650373/


All Articles