我正在使用导航抽屉为我的Android应用程序。我使用listview显示导航抽屉中的项目。我想使用列表视图的Listitem状态颜色,但它不工作,不显示不同状态的不同颜色。我代码是:
navigation_drawer.xml
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- The main content view -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<ListView
android:id="@+id/left_drawer"
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@drawable/navigation_item_selector"
android:cacheColorHint="#00000000"
android:choiceMode="singleChoice"
android:divider="@color/side_navigation_list_divider_color"
android:dividerHeight="1dp" />
</android.support.v4.widget.DrawerLayout>
navigation_item_selector.xml
<!-- Even though these two point to the same resource, have two states so the drawable will invalidate itself when coming out of pressed state. -->
<item android:drawable="@color/gray_back" android:state_pressed="true"/>
<item android:drawable="@color/red" android:state_activated ="true" android:state_selected="true"/>
<item android:drawable="@drawable/abs__ab_solid_light_holo"/>
</selector>