0

我正在尝试将 ListView 的突出显示颜色从默认的橙色/黄色更改。我尝试过设置android:listSelector,但这会导致点击的行被永久选中。请问如何更改突出显示颜色或防止行保持选中状态?

4

1 回答 1

0

您必须使用自定义 Listview 来更改 Bg 和 BgHover,例如:

可绘制文件夹:

渐变bg.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <!-- Gradient Bg for listrow -->
    <gradient
        android:angle="270"
        android:centerColor="#fdfdfd"
        android:endColor="#f8f8f8"
        android:startColor="#fdfdfd" />

</shape>

gradient_bg_hover.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <!-- Gradient Bg for listrow -->
    <gradient
        android:angle="270"
        android:centerColor="#fdfdfd"
        android:endColor="#f8f8f8"
        android:startColor="#f8f8f8" />

</shape>  

list_selector.xml

<!-- Selector style for listrow -->
<item android:drawable="@drawable/gradient_bg" android:state_pressed="false" android:state_selected="false"/>
<item android:drawable="@drawable/gradient_bg_hover" android:state_pressed="true"/>
<item android:drawable="@drawable/gradient_bg_hover" android:state_pressed="false" android:state_selected="true"/>

现在使用这个 list_selector.xml 到 Listview 的背景

于 2013-10-30T08:30:54.417 回答