Change the color of divider in LinearLayout

后端 未结 3 1024
攒了一身酷
攒了一身酷 2021-02-20 09:41

May I know how I can change the color of divider in LinearLayout?



        
相关标签:
3条回答
  • 2021-02-20 09:52

    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.

    0 讨论(0)
  • 2021-02-20 10:03

    This is how I did it

          <ImageView
                android:id="@+id/imgVwmarkupborder"
                android:layout_width="280dp"
                android:layout_height="2dp"
                android:src="@android:color/white" />
    
    0 讨论(0)
  • 2021-02-20 10:05
    <View
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:background="@android:color/white"/>
    

    In my method i am use this one..

    0 讨论(0)
提交回复
热议问题