『ANDROID』去除或替换listview 默认的点击选中时的颜色
2014-10-18 23:12
501 查看
原文地址:http://blog.csdn.net/yangdeli888/article/details/7887702
我们在定义一个drawable的时候可以通过xml定义的drawable对象。它使得一个图片能在不同的状态下显示不同的图案,比如一个Button,它有pressed,focused,或者其它状态,通过使用state list drawable,你就可以为每种状态提供不同的图片。
先看一个范例:
XML file saved at
[java] view
plaincopy
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:state_enabled="true" android:state_window_focused="false"
android:drawable="@drawable/button_pressed" /> <!-- pressed,enable等多个属性 -->
<item android:state_focused="true"
android:drawable="@drawable/button_focused" /> <!-- focused -->
<item android:state_hovered="true"
android:drawable="@drawable/button_focused" /> <!-- hovered -->
<item android:drawable="@drawable/button_normal" /> <!-- default -->
</selector>
This layout XML applies the state list drawable to a Button:
[java] view
plaincopy
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="@drawable/button" />
android:drawable 放一个drawable资源
android:state_pressed 是否按下,如一个按钮触摸或者点击。
android:state_focused 是否取得焦点,比如用户选择了一个文本框。
android:state_hovered 光标是否悬停,通常与focused state相同,它是4.0的新特性
android:state_selected 被选中,它与focus state并不完全一样,如一个list view 被选中的时候,它里面的各个子组件可能通过方向键,被选中了。
android:state_checkable 组件是否能被check。如:RadioButton是可以被check的。
android:state_checked 被checked了,如:一个RadioButton可以被check了。
android:state_enabled 能够接受触摸或者点击事件
android:state_activated 被激活(这个麻烦举个例子,不是特明白)
android:state_window_focused 应用程序是否在前台,当有通知栏被拉下来或者一个对话框弹出的时候应用程序就不在前台了
注意:如果有多个item,那么程序将自动从上到下进行匹配,最先匹配的将得到应用。(不是通过最佳匹配)
如果一个item没有任何的状态说明,那么它将可以被任何一个状态匹配。
详细的请看官方的API,那里写的更详细~!http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList
1.去除默认的点击选中时的颜色
(1)设置列表layout的backgroudcolor属性就OK了。
(2)android:focusable="false" android:focusableInTouchMode="false"
android:cacheColorHint="#00000000" android:listSelector="#00000000"
2.替换listview 默认的点击选中时的颜色
设置listivew的listSelector属性就可以了。
我们在定义一个drawable的时候可以通过xml定义的drawable对象。它使得一个图片能在不同的状态下显示不同的图案,比如一个Button,它有pressed,focused,或者其它状态,通过使用state list drawable,你就可以为每种状态提供不同的图片。
先看一个范例:
XML file saved at
res/drawable/button.xml:
[java] view
plaincopy
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:state_enabled="true" android:state_window_focused="false"
android:drawable="@drawable/button_pressed" /> <!-- pressed,enable等多个属性 -->
<item android:state_focused="true"
android:drawable="@drawable/button_focused" /> <!-- focused -->
<item android:state_hovered="true"
android:drawable="@drawable/button_focused" /> <!-- hovered -->
<item android:drawable="@drawable/button_normal" /> <!-- default -->
</selector>
This layout XML applies the state list drawable to a Button:
[java] view
plaincopy
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="@drawable/button" />
android:drawable 放一个drawable资源
android:state_pressed 是否按下,如一个按钮触摸或者点击。
android:state_focused 是否取得焦点,比如用户选择了一个文本框。
android:state_hovered 光标是否悬停,通常与focused state相同,它是4.0的新特性
android:state_selected 被选中,它与focus state并不完全一样,如一个list view 被选中的时候,它里面的各个子组件可能通过方向键,被选中了。
android:state_checkable 组件是否能被check。如:RadioButton是可以被check的。
android:state_checked 被checked了,如:一个RadioButton可以被check了。
android:state_enabled 能够接受触摸或者点击事件
android:state_activated 被激活(这个麻烦举个例子,不是特明白)
android:state_window_focused 应用程序是否在前台,当有通知栏被拉下来或者一个对话框弹出的时候应用程序就不在前台了
注意:如果有多个item,那么程序将自动从上到下进行匹配,最先匹配的将得到应用。(不是通过最佳匹配)
如果一个item没有任何的状态说明,那么它将可以被任何一个状态匹配。
详细的请看官方的API,那里写的更详细~!http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList
1.去除默认的点击选中时的颜色
(1)设置列表layout的backgroudcolor属性就OK了。
(2)android:focusable="false" android:focusableInTouchMode="false"
android:cacheColorHint="#00000000" android:listSelector="#00000000"
2.替换listview 默认的点击选中时的颜色
设置listivew的listSelector属性就可以了。
相关文章推荐
- android listview去掉分割线 && 去除或替换listview 默认的点击选中时的颜色
- 去除或替换listview 默认的点击选中时的颜色
- 去除或替换listview 默认的点击选中时的颜色
- Android中listview选中一个列表变为选中颜色,其他变为默认颜色
- android gridview默认显示部分数据,点击按钮显示全部,再点击回到默认状态,选中变颜色
- 怎么去除android listview的默认点击效果
- android listview改变选中行字体颜色
- Android ListView 去除边缘阴影、选中色、拖动背景色等
- Android ListView 去除底色、选中色、阴影
- 【android】listview改变选中行字体颜色
- Android ListView 去除边缘阴影、选中色、拖动背景色等
- Android ListView 去除边缘阴影、选中色、拖动背景色等
- 点击listitem按下效果替换默认颜色
- android上改变listView的选中颜色 (转)
- 在android中当点击ListView的item条目时,使item中的TextView的文字变成其他颜色作为标志
- Android ListView 去除边缘阴影、选中色、拖动背景色等
- android上改变listView的选中颜色
- android上改变listView的选中颜色
- Android ListView 去除边缘阴影、选中色、拖动背景色等
- 【android】listview改变选中行字体颜色