User3
User3

Reputation: 2535

Navigation Drawer change the Icon and text color of highlighted item

I am trying to change the icon of a nav drawer item when it is selected. I prepared the following file for the same:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/icon_milestone_selected" android:state_pressed="true"/>
    <item android:drawable="@drawable/icon_milestone_selected" android:state_focused="true"/>
    <item android:drawable="@drawable/icon_milestone_static"/>

</selector>

However the icon only changes when its touched, when the nav drawer is dismissed and opened again it does not give me the changed icon. What am I missing here?

Upvotes: 1

Views: 2794

Answers (1)

romtsn
romtsn

Reputation: 11982

Just add this line:

<item android:drawable="@drawable/icon_milestone_selected" android:state_pressed="false" state_activated="true"/>

It should work.

Upvotes: 2

Related Questions