Android 导航抽屉高亮显示所选项目不工作

Android 导航抽屉高亮显示所选项目不工作,android,android-layout,Android,Android Layout,我试图突出显示选定的导航抽屉项目,但它不起作用。它仅在按下项目时高亮显示,但在选择项目后不会保持高亮显示 我有以下代码: 列表视图: <ListView android:id="@+id/drawer_listview" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:choiceMode="single

我试图突出显示选定的导航抽屉项目,但它不起作用。它仅在按下项目时高亮显示,但在选择项目后不会保持高亮显示

我有以下代码:

列表视图:

<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"/>
据我所知,选择器中的
状态_activated=“true”
是在选中/选择listView项时出现的。但它不起作用

编辑:
我为行布局设置了
android:background=“@drawable/list\u selector\u holo\u light”
,现在它正在工作,但我仍然不知道为什么listSelector不工作。

您为列表项设置了背景色吗


如果是这样,您是否尝试过android:drawSelectorOnTop=“true”?

您使用的是哪个版本的android

我认为state_activated适用于API 11级及更高级别

我经历过这种情况,为了处理Pre-Honeycom,我为ListView创建了一个自定义适配器,并在
getView
方法中编写了以下代码:

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
     if (mListView.isItemChecked(position)) {
           holder.tvDrawerItem.setBackgroundColor(R.drawable.list_activated_holo);
     } else {
           holder.tvDrawerItem.setBackgroundColor(mContext.getResources().getColor(android.R.color.transparent));
     }
}

其中
drawerList
是您的导航栏的列表

您可以在为导航抽屉列表(mDrawerList.setOnItemClickListener)设置单击侦听器的位置共享代码吗?
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
     if (mListView.isItemChecked(position)) {
           holder.tvDrawerItem.setBackgroundColor(R.drawable.list_activated_holo);
     } else {
           holder.tvDrawerItem.setBackgroundColor(mContext.getResources().getColor(android.R.color.transparent));
     }
}
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    ...
    android:background="?android:attr/activatedBackgroundIndicator"
    android:minHeight="?android:attr/listPreferredItemHeightSmall"/>
drawerList.setItemChecked(currentPosition,true);