Issue
I am trying to change the iconTint
of the favorites
menuItem
in the bottomNavigationView
.
To achieve so, I've tried the following:
- Creating a
selector
with colors - Creating a
selector
with drawables - Programatically setting icon drawable
- programatically setting
iconItemTint
ofbottomNavigationView
to null - Using colored icon drawables, instead of
iconItemTint
- Setting the icon of
favorites
to the drawable selector - Setting the
background
offavorites
to the desired color - Setting
iconTint
offavorites
to desired color
None of the above solutions worked for me. Then I figured that it might be because I'm using com.google.android.material.bottomnavigation.BottomNavigationView
instead of android.support.design.widget.BottomNavigationView
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
app:labelVisibilityMode="labeled"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
app:itemTextColor="#232323"
app:menu="@menu/bottom_nav_menu" />
My bottom_nav_menu
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
...
<item
android:title="Favorites"
android:id="@+id/btn_favorites"
android:enabled="true"
android:background="@color/red_heart"
android:icon="@drawable/ic_favorite_red"
app:showAsAction="ifRoom" />
...
Here is a screenshot of my app:
The selected color is blue for all menuItems
. I want the favorites
to have the color #ff4444
(pale red) when selected.
Solution
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_gravity="bottom"
android:layout_marginBottom="0dp"
app:itemTextColor="@color/bootom_text_color"
app:itemIconTint="@color/bootom_text_color"
android:background="@color/bottom_color"
app:elevation="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:menu="@menu/bottom_navigation" />
create colour.xml in values
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:color="#FFFF00" />
<item android:color="@color/white" /> </selector>
Answered By - Tarun Umath
Answer Checked By - Senaida (JavaFixing Volunteer)