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>
Have you heard about the wrapper project called BottomBar of Roughike which makes the use of BottomNavigationView easier? Project can be found here.
I suggest you to use this project which is up to date and has contribution in a high level. If you refer to use this, You can simply insert the below code to change the colors when clicked on tabs and do much more customized stuff:
So basically what I do here, I color unselected tabs to
#7E7E7E
and clear the filter for coloring from selected ones so they appear with their original color of their icon. Of course, you can fill with another color when selected as well, that's up to you.Hope this helps you!
Cheers,
Renc
here is simple solution to your question
the selector
res/drawable/tab_color_selector.xml
:update tab item selector color what your required to.
In my situation, I used BottomNavigationBarEx plugin. So, I had to do it like below:
In my res/layout/layout_navigation_view.xml:
Added
app:itemIconTint="@drawable/bottom_nav_colors"
. Since, I only used icons. So if you have text add this:app:itemTextColor="@drawable/bottom_nav_colors"
also.Then in res/drawable directory (because
selector
s need to include indrawable
oranimatable
directory) add theselector
(as others mentioned):Then in res/values/colors.xml add your select and unselect colors, as ex:
create a color directory in res folder and create your xml file for customize your bottom navigation items:
res/color/bottom_nav_color.xml:
and in your
BottomNavigationView
setapp:itemTextColor
andapp:itemIconTint
values to @color/bottom_nav_color1-make file xml in drawble with name of
navigation_view_colored.xml
and put2-add xml you create to itemIconTint