Android默认情况下,在点按以显示点按状态时会显示绿色。我想将该颜色更改为其他颜色,以便在列表视图中的故事被点击时显示更改的颜色。
感谢任何帮助。
答案 0 :(得分:5)
只需在ListView中定义 android:listSelector
属性。
<ListView
android:id="@+id/ListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:listSelector="@android:color/darker_gray">
</ListView>
根据chirag的评论,我想建议此链接作为参考:http://developer.android.com/reference/android/R.attr.html#listSelector
只需检查上面链接中的第一行:“Drawable用于指示列表中当前选定的项目。”
只需在Drawable文件夹中定义ListSelector xml文件,然后输入以下代码:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/bg_list_item_selected"/>
<item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/bg_list_item_selected"/>
<item android:state_focused="true" android:drawable="@drawable/bg_list_item_selected"/>
<item android:state_focused="false" android:state_pressed="false" android:drawable="@drawable/bg_list_item_normal"/>
</selector>
并将 android:background =“@ drawable / listSelctor”提供给自定义列表视图行文件。是的,它是自定义列表视图的自定义列表视图行文件。
答案 1 :(得分:0)
通过咨询老年人和同事,我得到了更好的答案,其中说:
添加一行listselector和其他属性,并将列表选择器的路径设置为最近放置在drawable文件夹中的图像。
<ListView
android:id="@+id/ListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:listSelector = "@drawable/list_selector">
</ListView>
清理/构建项目并运行。
我希望这是执行此任务最简单的方法......这对我很有用......希望这也适合你。