我希望能够突出显示所选的导航抽屉项,但它不起作用。只有在按下选项时才会高亮显示,但选定项后不会保持高亮。
我有以下代码:
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" />
选择器:
<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"/>
可绘制对象是由Android Holo Colors生成的九宫格文件。
在我的活动中:
mListView.setAdapter(mAdapter);
mListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
mListView.setItemChecked(1, true); // Testing
mListView.setSelection(1); // Testing
据我所知,选择器中的
state_activated="true"
是当listView项目被选中/选中时。但它不起作用。
编辑:
我为行布局设置了android:background="@drawable/list_selector_holo_light"
,现在它可以工作了,但我仍然不知道为什么listSelector不起作用。