How to change only the color of the lines (stripes) in a ListView ?

    1 answer 1

    In the markup file:

    Property android:divider set the color of the separator:

     android:divider="#RRGGBB" 

    At the same time, it is necessary to set the height of the delimiter android:dividerHeight (otherwise the delimiter will not be visible):

     android:dividerHeight="4px" 

    Full example:

     <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="#RRGGBB" android:dividerHeight="4px"/> </LinearLayout> 

    In code

    Using the methods ListView.setDivider , ListView.setDividerHeight and one of the gradient classes:

    • ColorDrawable for a normal delimiter:

       list.setDivider(new ColorDrawable(0xAARRGGBB)); list.setDividerHeight(4); 

      (using context.getResources().getColor(R.color.некоторый_id) you can get the color specified in the resources)

    • GradientDrawable :

       ListView list = ... int[] colors = {0, 0xFFFF0000, 0}; // красный цвет для примера list.setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colors)); list.setDividerHeight(4); 

    In both, you must first set the color of the separator, and then its height, otherwise the separator will not be visible.