Reputation: 78004
I want to change color of ListView
separator line.
Upvotes: 411
Views: 261104
Reputation: 1661
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);
Upvotes: 166
Reputation: 5742
using programetically
// Set ListView divider color
lv.setDivider(new ColorDrawable(Color.parseColor("#FF4A4D93")));
// set ListView divider height
lv.setDividerHeight(2);
using xml
<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="#44CC00"
android:dividerHeight="4px"/>
</LinearLayout>
Upvotes: 1
Reputation: 247
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>
Upvotes: 3
Reputation: 2427
There are two ways to doing the same:
You may set the value of android:divider="#FFCCFF" in layout xml file. With this you also have to specify height of divider like this android:dividerHeight="5px".
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/lvMyList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#FFCCFF"
android:dividerHeight="5px"/>
</LinearLayout>
You may also do this by programmatically...
ListView listView = getListView();
ColorDrawable myColor = new ColorDrawable(
this.getResources().getColor(R.color.myColor)
);
listView.setDivider(myColor);
listView.setDividerHeight();
Upvotes: 7
Reputation: 19283
For a single color line use:
list.setDivider(new ColorDrawable(0x99F10529)); //0xAARRGGBB
list.setDividerHeight(1);
It's important that DividerHeight is set after the divider, else you won't get anything.
Upvotes: 90
Reputation: 706
XML version for @Asher Aslan cool effect.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:angle="180"
android:startColor="#00000000"
android:centerColor="#FFFF0000"
android:endColor="#00000000"/>
</shape>
Name for that shape as: list_driver.xml under drawable folder
<ListView
android:id="@+id/category_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="@drawable/list_driver"
android:dividerHeight="5sp" />
Upvotes: 11
Reputation: 8520
Use android:divider="#FF0000"
and android:dividerHeight="2px"
for ListView.
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="#0099FF"
android:dividerHeight="2px"/>
Upvotes: 0
Reputation: 131
You can also get the colors from your resources by using:
dateView.setDivider(new ColorDrawable(_context.getResources().getColor(R.color.textlight)));
dateView.setDividerHeight(1);
Upvotes: 13
Reputation: 14354
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>
Upvotes: 771