-1
我創建了一個簡單的android滑動菜單,問題是當我點擊它時項目顏色不會改變。項目顏色不改變點擊
這裏是我的XML資源:
list_item_bg_pressed.xml:(可繪製下)
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient
android:startColor="@color/list_background_pressed"
android:endColor="@color/list_background_pressed"
android:angle="90" />
</shape>
list_item_bg_normal.xml:(可繪製下)
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="@color/menubg"
android:endColor="@color/menubg"
android:angle="90" />
</shape>
列表selector.xml:(在Draw下能)
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/list_item_bg_normal" android:state_activated="false"/>
<item android:drawable="@drawable/list_item_bg_pressed" android:state_pressed="true"/>
<item android:drawable="@drawable/list_item_bg_pressed" android:state_activated="true"/>
</selector>
activity_main.xml中:(下佈局)
<com.example.app.MainLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/drawer_layout"
>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/menu_listview"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@color/menubg"
android:cacheColorHint="#00000000"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:listSelector="@drawable/list_selector"
android:divider="@color/list_divider"
android:dividerHeight="1dp"
>
</ListView>
</LinearLayout>
謝謝你:)工作。 – wissem46