Change the color of divider in LinearLayout

ぃ、小莉子 提交于 2019-12-04 02:43:46

It looks like android:divider attribute doesn't accept a color value. So you have to create a separate divider drawable in order to get it works:

divider.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">

    <size android:width="1dip" />
    <solid android:color="#f00" />

</shape>

layout.xml

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="48dp"
    android:orientation="horizontal"
    android:divider="@drawable/divider"
    android:dividerPadding="12dip"
    android:showDividers="middle"
    android:background="#ff2d2d2d" >

Also, please note that android:divider is only available in android 3.0 or higher and it doesn't work in previous android versions.

This is how I did it

      <ImageView
            android:id="@+id/imgVwmarkupborder"
            android:layout_width="280dp"
            android:layout_height="2dp"
            android:src="@android:color/white" />
<View
    android:layout_width="fill_parent"
    android:layout_height="1dp"
    android:background="@android:color/white"/>

In my method i am use this one..

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!