我想改变ListView分隔线的颜色。任何帮助都将不胜感激。
当前回答
使用programetically
// Set ListView divider color
lv.setDivider(new ColorDrawable(Color.parseColor("#FF4A4D93")));
// set ListView divider height
lv.setDividerHeight(2);
使用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>
其他回答
你可以在布局xml文件中使用android:divider="#FF0000"设置这个值。如果你要改变颜色/可绘制,你也必须设置/重置分割线的高度。
<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>
在xml文件中使用下面的代码
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#000000"
android:dividerHeight="1dp">
</ListView>
你也可以使用以下方法从资源中获取颜色:
dateView.setDivider(new ColorDrawable(_context.getResources().getColor(R.color.textlight)));
dateView.setDividerHeight(1);
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" />
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。谷歌服务插件没有它就不能正常工作。