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