Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

item selected color in android BottomNavigationView

I refer this. Schedules Activity is appeared when I click Schedules, but first item color (Favorites) is always selected. It doesn't change Schedules item color from Favorites item color. And also, third item (Music). I use android:state_checked NOT android:state_enabled." If working with startActivity, it doesn't change Schedules item color from Favorites item color. If not, it change color. How to solve this color select problems.

activity_main.xml

app:itemIconTint="@drawable/nav_item_color_state" app:itemTextColor="@drawable/nav_item_color_state" app:menu="@menu/bottom_navigation_main" 

@drawable/nav_item_color_state

<selector xmlns:android="http://schemas.android.com/apk/res/android">     <item android:color="@color/white" android:state_enabled="true" />     <item android:color="@color/colorPrimaryDark" android:state_enabled="false" /> </selector> 
like image 581
WPG Avatar asked Feb 15 '17 08:02

WPG


People also ask

How do I change my BottomNavigationView color?

To change the color of your tabs to a specific color, tap Basic colors and select the color you like.

How to use BottomNavigationView in Android?

BottomNavigationView makes it easy for users to explore and switch between top-level views with a single tap. There should be a minimum of 3 top-level views and a maximum of 5. If Destinations are more than 5 then use the Navigation Drawer. When the user taps on the icon it will change the top-level view accordingly.

What is BottomNavigationView?

com.google.android.material.bottomnavigation.BottomNavigationView. Represents a standard bottom navigation bar for application. It is an implementation of material design bottom navigation. Bottom navigation bars make it easy for users to explore and switch between top-level views in a single tap.


2 Answers

create a color directory in res folder and create your xml file for customize your bottom navigation items:

res/color/bottom_nav_color.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/your_color" />      <item android:state_checked="false" android:color="@color/your_color"/> </selector> 

and in your BottomNavigationView set app:itemTextColor and app:itemIconTint values to @color/bottom_nav_color

<android.support.design.widget.BottomNavigationView    xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    android:id="@+id/main_navigation"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:layout_alignParentBottom="true"    android:background="@color/actionBarColor"    app:menu="@menu/my_navigation_items"    app:itemTextColor="@color/bottom_nav_color"    app:itemIconTint="@color/bottom_nav_color"/>  
like image 59
Mohammad Hosein Heidari Avatar answered Sep 19 '22 20:09

Mohammad Hosein Heidari


  1. Make a xml file in the drawable folder with the name of navigation_view_colored.xml and put this inside:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android">   <item android:state_checked="false" android:color="@color/gray" />   <item android:state_checked="true" android:color="@color/blue" /> </selector> 
  1. Add the xml you created to app:itemIconTint
<com.google.android.material.bottomnavigation.BottomNavigationView     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:id="@+id/bottom_navigation"     android:layout_alignParentBottom="true"     app:itemIconTint="@drawable/navigation_view_colored"     app:itemTextColor="@color/blue"     app:menu="@menu/bottom_navigation"     android:background="?android:attr/windowBackground"/> 
like image 24
jenos kon Avatar answered Sep 17 '22 20:09

jenos kon