Is there a way to have a different icon / color for the selected Android BottomNavigationView state?

Below is the XML for my current BottomNavigationView method. Currently, all three icon icons are blank icons of the same color. I would like to be able to present a completed version of the icon when this state is selected, and also possibly change the color so that it becomes obvious, this is the current state of the icon. The following image is an example of what I mean.

Example of changing the icon color for the selected state

<?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:id="@+id/action_favorites"
        android:enabled="true"
        android:icon="@drawable/icon_flyer"
        android:title="Flyer"
        app:showAsAction="ifRoom" />
    <item
        android:id="@+id/action_schedules"
        android:enabled="true"
        android:icon="@drawable/icon_list"
        android:title="List"
        app:showAsAction="ifRoom" />
    <item
        android:id="@+id/action_music"
        android:enabled="true"
        android:icon="@drawable/icon_contact"
        android:title="Contact"
        app:showAsAction="ifRoom" />
</menu>
+4
source share
3 answers

, , "itemIconTint" BottomNavigationView. , itemTextColor. , BottomNavigationView:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="@color/green" android:state_pressed="true" />
    <item android:color="@color/green" android:state_checked="true" />
    <item android:color="@color/gray" />
</selector>

"android: state_pressed" - . "Android: state_checked" - .

BottomNavigationView. , "" . :

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/ic_favorites_filled" android:state_checked="true" />
    <item android:drawable="@drawable/ic_favorites" />
</selector>
+4

StateDrawable . xml :

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/button_pressed_green"
          android:state_pressed="true" />
    <item android:drawable="@drawable/button_normal" />
</selector>

xml , ( ), , .

+1

1:

2: . "bottom_navigation_icon" () . :

 <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:drawable="@drawable/ic_home_active" 
    android:state_checked="true"/>
        <item android:drawable="@drawable/ic_home_inactive"/>
    </selector>

3: :

android:icon="@drawable/bottom_navigation_icon"

. , , , .

0

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


All Articles