简体   繁体   English

导航抽屉更改突出显示的项目的图标和文本颜色

[英]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? 我在这里想念什么?

Just add this line: 只需添加以下行:

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

It should work. 它应该工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM