我想改变ListView分隔线的颜色。任何帮助都将不胜感激。


当前回答

有两种方法可以做到这一点:

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();

其他回答

有两种方法可以做到这一点:

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();

你也可以使用以下方法从资源中获取颜色:

dateView.setDivider(new ColorDrawable(_context.getResources().getColor(R.color.textlight)));
dateView.setDividerHeight(1);

对于单色线使用:

list.setDivider(new ColorDrawable(0x99F10529));   //0xAARRGGBB
list.setDividerHeight(1);

重要的是,将DividerHeight设置在分隔符之后,否则你将得不到任何东西。

ListView使用android:divider="#FF0000"和android:dividerHeight="2px"。

<ListView 
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="#0099FF"
android:dividerHeight="2px"/>

或者你可以编码:

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