更改ListView高亮颜色

时间:2013-10-30 07:56:35

标签: android

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

1 个答案:

答案 0 :(得分:0)

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

可绘制文件夹:

<强> gradient_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的背景