Frage

I am implementing navigation drawer in my application with help of appCompat libs. I want to remain highlighted the item which was clicked how can i perform so .enter image description here

War es hilfreich?

Lösung

Create the background of navigation drawer item background as following

background.xml

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

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

</selector>

then add the following part of code while clicking on the item

mDrawerList.setItemChecked(position, true);
mDrawerList.setSelection(position);
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top