Android 如何更改listview中的分隔符颜色?

Android 如何更改listview中的分隔符颜色?,android,Android,我需要更改listview中的分隔符颜色。下面引用了我用来完成此任务的代码: <ListView android:id="@+id/restaurant_list_widget" android:layout_width="1px" android:layout_height="1px" android:layout_weight="1" android:background="@drawable/list" android:divider="#FF

我需要更改listview中的分隔符颜色。下面引用了我用来完成此任务的代码:

<ListView
    android:id="@+id/restaurant_list_widget"
    android:layout_width="1px"
    android:layout_height="1px"
    android:layout_weight="1" android:background="@drawable/list"
    android:divider="#FFFFFF"
    android:dividerHeight="4px">
</ListView>  

我仍然有一个1倍宽的黑色分隔器。我做错了什么

更新:ListItem

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="5dp"
    android:background="@color/list_background">
        <TextView
            android:id="@+id/restaurant_list_item_name"
            android:layout_marginBottom="4dp"
            android:textStyle="bold"
            android:textSize="15dp"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:textColor="#fff"
            android:text="Restaurant Name Goes Here"></TextView>
        <TextView
            android:id="@+id/restaurant_list_item_detail"
            android:textSize="10dp"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"></TextView>    
</LinearLayout>

您只需设置ListView的分隔符属性:

android:divider="#FFCC00"
   android:divider="@android:color/white"
   android:dividerHeight="0.2dp"

我已经尝试过:

 <ListView 
    android:id="@+id/ListView01" 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:divider="@color/redBackground"
    android:dividerHeight="1dip">
 </ListView>

颜色值在colors.xml中:

<color name="redBackground">#C60202</color>
<resources>
 <drawable name="sage">#cceebb</drawable>
</resources>
#C60202
其工作良好,显示分隔器颜色为红色,高度为1IP

更新:
只要检查一下你的listview布局,你提到了1px表示
布局宽度
布局高度
,你正在设置4px表示
分割高度
我想问题出在你的
listview
布局宽度
布局高度

设置
layout\u width=“fill\u parent”
layout\u height=“wrap\u content”

否则

在Listview中设置分隔符颜色和高度的方法

  • 您可以使用
    android:divider=“#FF0000”
    在布局xml文件中设置此值

  • 修改分隔器时,还应设置/重置分隔器的高度

     <ListView 
        android:id="@+id/android:list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:divider="#FFCC00"
            android:dividerHeight="4px"/>
    

  • 你可以像我一样

    方法1:

  • 在res/values/colors.xml中,放置以下内容:

    <resources>
     <color name="sage">#cceebb</color>
    </resources>
    
    方法2:

    在res/values/colors.xml中:

    <color name="redBackground">#C60202</color>
    
    <resources>
     <drawable name="sage">#cceebb</drawable>
    </resources>
    

    希望有帮助

    您应该在ListView中添加以下代码:

    android:divider="#FFCC00"
    
       android:divider="@android:color/white"
       android:dividerHeight="0.2dp"
    

    styles.xml中有一种不同的方法,只需添加到style标记中即可

    <item name="android:divider">#B6B6B6</item>
    
    #b6b6
    
    e、 g:

    
    #303F9F
    #3F51B5
    #FF5722
    @颜色/文本颜色主
    @颜色/文本颜色辅助
    #B6B6B6
    @颜色/窗口背景
    
    您必须添加以下代码

    <ListView
            android:id="@+id/restaurant_list_widget"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:divider="#FFFFFF"
            android:dividerHeight="0.5dp" />
    

    可以引用此链接。您可以在指定列表项的位置发布另一个xml。检查您在那里设置的背景色。