I want to change color of ListView
separator line. Any help would be appreciated.
我想改变ListView分隔线的颜色。如有任何帮助,我们将不胜感激。
8 个解决方案
#1
722
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.
您可以在一个使用android的布局xml文件中设置这个值:分隔符=“#FF0000”。如果你正在改变颜色/drawable,你也必须设置/重置分隔符的高度。
<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>
#2
159
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
希望它能帮助
#3
83
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.
把除数设成除法是很重要的,否则你什么也得不到。
#4
10
You can also get the colors from your resources by using:
你也可以通过以下方式获得你的资源的颜色:
dateView.setDivider(new ColorDrawable(_context.getResources().getColor(R.color.textlight)));
dateView.setDividerHeight(1);
#5
9
XML version for @Asher Aslan cool effect.
XML版本的@Asher阿斯兰酷效应。
<?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
该形状的名称为:list_driver。xml在可拉的文件夹
<ListView
android:id="@+id/category_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="@drawable/list_driver"
android:dividerHeight="5sp" />
#6
4
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".
您可以在布局xml文件中设置android的值:分隔符="#FFCCFF"。这样,你还必须指定像这样的android:分隔高度="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();
#7
2
Use below code in your xml file
在xml文件中使用以下代码。
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#000000"
android:dividerHeight="1dp">
</ListView>
#8
0
Use android:divider="#FF0000"
and android:dividerHeight="2px"
for ListView.
使用android:分隔符="#FF0000"和android:dividerHeight="2px"的ListView。
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="#0099FF"
android:dividerHeight="2px"/>
#1
722
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.
您可以在一个使用android的布局xml文件中设置这个值:分隔符=“#FF0000”。如果你正在改变颜色/drawable,你也必须设置/重置分隔符的高度。
<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>
#2
159
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
希望它能帮助
#3
83
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.
把除数设成除法是很重要的,否则你什么也得不到。
#4
10
You can also get the colors from your resources by using:
你也可以通过以下方式获得你的资源的颜色:
dateView.setDivider(new ColorDrawable(_context.getResources().getColor(R.color.textlight)));
dateView.setDividerHeight(1);
#5
9
XML version for @Asher Aslan cool effect.
XML版本的@Asher阿斯兰酷效应。
<?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
该形状的名称为:list_driver。xml在可拉的文件夹
<ListView
android:id="@+id/category_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="@drawable/list_driver"
android:dividerHeight="5sp" />
#6
4
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".
您可以在布局xml文件中设置android的值:分隔符="#FFCCFF"。这样,你还必须指定像这样的android:分隔高度="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();
#7
2
Use below code in your xml file
在xml文件中使用以下代码。
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#000000"
android:dividerHeight="1dp">
</ListView>
#8
0
Use android:divider="#FF0000"
and android:dividerHeight="2px"
for ListView.
使用android:分隔符="#FF0000"和android:dividerHeight="2px"的ListView。
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="#0099FF"
android:dividerHeight="2px"/>