如何在点击时将背景渐变更改为某些内容并在手指释放时获取原始渐变...我使用列表视图适配器创建的列表确实更改为渐变但在我抬起时不会更改回原始渐变手指.. xmls下面
main.xml中
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#EDEDED"
android:dividerHeight="1dp"
android:listSelector="@drawable/list_selector"
/>
list_selector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Selector style for listrow -->
<item android:state_focused="true"
android:drawable="@drawable/gradient_bg_hover"
/>
<item
android:state_selected="false"
android:state_pressed="false"
android:drawable="@drawable/gradient_bg" />
<item android:state_pressed="true"
android:drawable="@drawable/gradient_bg_hover" />
<item android:state_selected="true"
android:state_pressed="false"
android:drawable="@drawable/gradient_bg_hover" />
</selector>
row_list.xml
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/txtListText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="15dp"
android:textSize="45sp"
/>
gradient_bg和gradient_bghover是渐变xml的..
答案 0 :(得分:0)
我想,你不能一次定义state_selected和state_pressed ......
工作的东西应该是这样的:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:drawable="@drawable/_bt_week_selected" />
<item android:state_focused="true" android:drawable="@drawable/_bt_week_selected"/>
<item android:state_pressed="true" android:drawable="@drawable/_bt_week_selected"/>
<item android:drawable="@drawable/_bt_week_normal"/>
</selector>
并将列表项(row_list)的背景设置为选择器...例如android:background="@drawable/selector"
...而不是使用android:listSelector="@drawable/list_selector"
我不知道你的工作是否正常......