我想改变ListView分隔线的颜色。任何帮助都将不胜感激。
当前回答
你也可以使用以下方法从资源中获取颜色:
dateView.setDivider(new ColorDrawable(_context.getResources().getColor(R.color.textlight)));
dateView.setDividerHeight(1);
其他回答
对于单色线使用:
list.setDivider(new ColorDrawable(0x99F10529)); //0xAARRGGBB
list.setDividerHeight(1);
重要的是,将DividerHeight设置在分隔符之后,否则你将得不到任何东西。
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>
该形状的名称为:可绘制文件夹下的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" />
在xml文件中使用下面的代码
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#000000"
android:dividerHeight="1dp">
</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();
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"/>
推荐文章
- 改变开关的“开”色
- 以编程方式将EditText的输入类型从PASSWORD更改为NORMAL,反之亦然
- 如何在隐藏和查看密码之间切换
- 在Android上调整一个大的位图文件到缩放输出文件
- 如何更改Android版本和代码版本号?
- Android Studio突然无法解析符号
- 应用程序重新启动而不是恢复
- 如何设置整个应用程序在纵向模式?
- Android中文本的阴影效果?
- 以编程方式设置TextView的布局权重
- Android -如何覆盖“后退”按钮,所以它不完成()我的活动?
- 如何从通知点击发送参数到一个活动?
- 导航目标xxx对于这个NavController是未知的
- 使用ConstraintLayout均匀间距的视图
- 文件google-services错误。模块根文件夹中缺少Json。谷歌服务插件没有它就不能正常工作。