How to change color of Android ListView separator line?

前端 未结 9 1549
时光取名叫无心
时光取名叫无心 2020-11-28 00:08

I want to change color of ListView separator line. Any help would be appreciated.

相关标签:
9条回答
  • 2020-11-28 01:03

    You can set this value in a layout xml file using android:divider="#FF0000". If you are changing the colour/drawable, you have to set/reset the height of the divider too.

    <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content">
    
      <ListView 
        android:id="@+id/android:list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:divider="#FFCC00"
        android:dividerHeight="4px"/>
    
    </LinearLayout>
    
    0 讨论(0)
  • 2020-11-28 01:04

    Use below code in your xml file

    <ListView 
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:divider="#000000" 
        android:dividerHeight="1dp">
    </ListView> 
    
    0 讨论(0)
  • 2020-11-28 01:11

    Or you can code it:

    int[] colors = {0, 0xFFFF0000, 0}; // red for the example
    myList.setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colors));
    myList.setDividerHeight(1);
    

    Hope it helps

    0 讨论(0)
提交回复
热议问题