I'm trying to highlight the selected nav drawer item but it doesn't work. it only highlights on pressing the items but does not remain highlighted after the item is selected.
I have the following code:
The ListView:
<ListView
android:id="@+id/drawer_listview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:choiceMode="singleChoice"
android:divider="@color/drawer_divider"
android:dividerHeight="@dimen/drawer_divider_height"
android:listSelector="@drawable/list_selector_holo_light" />
The Selector:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@android:color/transparent" android:state_window_focused="false"/>
<item android:drawable="@drawable/list_selector_disabled_holo_light" android:state_enabled="false" android:state_focused="true" android:state_pressed="true"/>
<item android:drawable="@drawable/list_selector_disabled_holo_light" android:state_enabled="false" android:state_focused="true"/>
<item android:drawable="@drawable/list_selector_background_transition_holo_light" android:state_focused="true" android:state_pressed="true"/>
<item android:drawable="@drawable/list_selector_background_transition_holo_light" android:state_focused="false" android:state_pressed="true"/>
<item android:drawable="@drawable/list_activated_holo" android:state_activated="true" />
<item android:drawable="@drawable/list_focused_holo" android:state_focused="true"/>
The drawables are 9-patch files generated with Android Holo Colors.
In my activity:
mListView.setAdapter(mAdapter);
mListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
mListView.setItemChecked(1, true); // Testing
mListView.setSelection(1); // Testing
As far as I know, the state_activated="true"
in the selector is when the listView item is checked/selected. but it doesn't work.
Edit:
I set android:background="@drawable/list_selector_holo_light"
for the row layout and now it is working, but I still have no idea why listSelector is not working.