Show clicked Item highlighted in Navigation Drawer Android

Sumit Patel picture Sumit Patel · Dec 9, 2013 · Viewed 8.1k times · Source

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

Answer

Vinil Chandran picture Vinil Chandran · Dec 29, 2014

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);