如何轻松更改ListView的默认颜色

问题描述:

我是Android新手,尝试在我的第一个应用程序上做一些设计,我更改了背景!现在我想改变listView(蓝色),Onclick的颜色,以及向上/向下滑动时的颜色。如何轻松更改ListView的默认颜色

是否可以更改XML文件,或者我必须以编程方式进行操作。

这里是一个截图把事情说清楚:

enter image description here

我把作为背景的列表视图这个XML:

<?xml version="1.0" encoding="utf-8"?> 

<item android:state_pressed="true" > 
    <shape> 
     <solid android:color="@color/Orange"/> 
    </shape> 
</item> 

我得到这个:

enter image description here

所以这不是我要找的,我想只改变默认的蓝色

+2

你只需要选择作为背景的row – Blackbelt 2015-03-13 13:54:14

创建一个选择文件,

/res/drawable/list_selectr.xml

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

    <item android:state_pressed="true" > 
     <shape> 
      <solid android:color="@color/list_item_pressed"/> 
     </shape> 
    </item> 

    <item> 
     <shape> 
      <solid android:color="@color/list_item_normal" /> 
     </shape> 
    </item> 

</selector> 

并将此xml作为listview条目的根标记的背景xml 。

比如,

<RelativeLayout android:background="@drawable/list_selector .../>" 
+0

查看编辑后的帖子, – 2015-03-13 14:13:44

+0

@ Strange90''会在您点击该项目时改变颜色。 – Apurva 2015-03-13 14:57:32

您还可以设置的ListView列表背景属性的XML

的android:背景= “#your_color”

+0

我不想改变背景颜色,我想改变Onclick颜色 – 2015-03-13 14:14:45

终于让我找到了一个解决方案,它是更简单,我发现的解决方案:

只需将它添加到您的xml文件的ListView中:android:listSelector="Yourcolor"

,如果你想只颜色 “焦点” 使用分离的XML文件: android:listSelector="Yourbackground"

XML实例:

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
 
<item android:state_pressed="true" > 
 
<shape> 
 
<solid android:color="@color/Orange"/> 
 
</shape> 
 
</item> 
 
<item> 
 
<shape> 
 
<solid android:color="@color/Transparent" /> 
 
</shape> 
 
</item> 
 
</selector>