我可以在不构建自定义列表视图的情况下更改ListView样式Android吗

时间:2010-06-26 10:42:44

标签: android listview

我想在不构建自定义行的情况下更改Listview的文本和背景颜色。这可能吗?

这是我的代码无效。

<ListView
    android:id="@android:id/list"
    android:textColor="#000000"           
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:cacheColorHint="#000000"/>

任何帮助都将不胜感激。

谢谢

1 个答案:

答案 0 :(得分:10)

首先,cacheColorHint与风格无关。 尝试观看Romain Guy's ListView presentation on the GoogleIO 2010。你会对它有很多了解。

关于风格:

我在我的应用上更改了一些内容。

使用ListView查看:

<ListView android:id="@id/android:list"
  android:layout_width="fill_parent" 
  android:layout_height="fill_parent"
  android:layout_weight="1"
  android:headerDividersEnabled="false"
  android:footerDividersEnabled="true"
  android:divider="@drawable/list_divider"
  android:dividerHeight="1dip"
  android:cacheColorHint="#FFFFFF"
/>

简短说明: 我刚离开footerDivider并将我的分隔符更改为渐变。

抽拉/ list_divider:

<?xml version="1.0" encoding="utf-8"?>
<layer-list
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape>
            <gradient
                android:startColor="#000000"
                android:centerColor="#CCCCCC"
                android:endColor="#FFFFFF"
                android:height="1px"
                android:angle="0" />
        </shape>
    </item>
</layer-list>

的RowLayout:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:paddingTop="2dp"
    android:paddingBottom="2dp"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:background="@android:color/white">

说明: 添加了白色背景。