I try to add two colors to the default colors in the BottomNavigationView (for two states of menu items) and a third color. To do this, in the drawable folder, created the file "bottom_nav_colors.xml" with selectors:

<?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/colorPrimaryDark"/> <item android:state_activated="true" android:color = "@color/colorAccent"/> <item android:color = "@color/colorGray" /> </selector > 

In the markup file "activity_main.xml" indicated as follows:

 <android.support.design.widget.BottomNavigationView android:id="@+id/navigation" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" android:background="?android:attr/windowBackground" app:menu="@menu/navigation_menu" app:itemIconTint="@drawable/bottom_nav_colors" app:itemTextColor="@drawable/bottom_nav_colors"/> 

However, I cannot figure out which method of the class "BottomNavigationView" from the class "MainActivity.java" (inherits from the class "MvpAppCompatActivity") to activate the state "activated" (or any other from the list: "accelerated", "active" etc.).

Well, or if you can not do this, how can you?

    1 answer 1

    Alas, in the "BottomNavigationView" this trick will fail. But if you use his successor from here , then everything is done quite easily:

     if (ServiceApp.getCartsGoodsNumber() > 0) { bnve.getBottomNavigationItemView(i).setIconTintList( ContextCompat.getColorStateList( bnve.getContext(), color.bottom_select_nav_colors)); addBadgeAt(bnve, i, ServiceApp.getCartsGoodsNumber()); } else { bnve.getBottomNavigationItemView(i).setIconTintList(null); if (mNavigation_20Badge != null) mNavigation_20Badge.hide(true); } 

    Here, the bnve class instance is "BottomNavigationViewExe" , and the addBadgeAt () method looks like this:

     private void addBadgeAt(BottomNavigationViewEx bnve, final int position, final int number) { // add badge mNavigation_20Badge = new QBadgeView(bnve.getContext()) .setBadgeNumber(number).setGravityOffset(12, 2, true) .bindTarget(bnve.getBottomNavigationItemView(position)); } 

    This method allows you to add a badge to the icon:

    Navigation bar based on "BottomNavigationViewExe"