本文介绍了如何改变的ListView所选项目的颜色(这不是一个自定义的ListView)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何更改自定义的ListView所选项目的颜色。但我不知道如何改变颜色正常的ListView。

我试过这样:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
    android:state_pressed="true"
    android:drawable="@color/light_blue"></item>
</selector>

But this just changes the color of Entire ListView. I dont want to implement CUSTOM ListView just for selector color change. Please provide a solution for this.

解决方案

Try it with a shape as the background, instead of a simple color. Here's an example from one of my projects:

listselector_blue.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
   <item android:state_pressed="true" android:drawable="@drawable/selector_state_blue"/>
   <item android:drawable="@color/transparent"/>
</selector>

selector_state_blue.xml:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <gradient
        android:angle="270"
        android:endColor="#FF91B2FF"
        android:startColor="#4491B2FF" />

    <corners android:radius="10px" />

</shape>

Layout xml of the Activity with the ListView:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ListView android:id="@+id/list1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:listSelector="@drawable/listselector_blue" />

</LinearLayout>

这篇关于如何改变的ListView所选项目的颜色(这不是一个自定义的ListView)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 23:02
查看更多