2

我正在为我的 android 应用程序使用导航抽屉。我正在使用列表视图来显示导航抽屉中的项目。我想为列表视图使用 Listitem 状态颜色,但它不起作用并且不为不同的状态显示不同的颜色。我的代码是:

导航抽屉.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>
4

0 回答 0