我使用list selector,但是不能很好的運行。點擊list item後可以獲得效果,但是在點擊item之前沒有任何效果出現。下面是 selector 的代碼:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_selected="false"
android:state_pressed="false"
android:drawable="@drawable/ic_launcher" />
<item android:state_pressed="true"
android:drawable="@drawable/headerplain" />
<item
android:state_focused="true"
android:state_pressed="false"
android:drawable="@drawable/headerplain" />
<item android:state_selected="true"
android:state_pressed="false"
android:drawable="@drawable/headerplain" />
</selector>
我已經把它應用到 listView
<ListView
android:id="@+id/listView123"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:listSelector="@drawable/list_selector"
android:drawSelectorOnTop="true"
android:focusable="true"
>
</ListView>
如何解決這個問題?謝謝!
listView中設置Selector是沒有錯的, 是不是list_selector 不太對,
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_selected="false"
android:state_pressed="false"
android:drawable="@drawable/ic_launcher" />
<item
android:state_focused="true"
android:state_pressed="false"
android:drawable="@drawable/headerplain" />
<item android:state_selected="true"
android:state_pressed="false"
android:drawable="@drawable/headerplain" />
<item android:state_pressed="true"
android:drawable="@drawable/headerplain" /> <!--這句放到最後試試--> > </selector>