我知道如何更改 CUSTOM ListView 的所选项目的颜色。但我不知道如何更改普通 ListView 的颜色。
我试过这个:
<ListView android:id="@id/android:list" android:layout_width="fill_parent" android:layout_height="fill_parent" android:drawSelectorOnTop="false" android:listSelector="@drawable/listitemselector">
<?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>
但这只是改变了整个 ListView 的颜色。我不想仅为选择器颜色更改实现 CUSTOM ListView。请为此提供解决方案。
最佳答案
尝试使用形状作为背景,而不是简单的颜色。这是我的一个项目中的示例:
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>
带有 ListView 的 Activity 的布局 xml:
<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>
关于android - 如何更改 ListView 的选定项的颜色(这不是自定义 ListView),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10160215/