自定义各边框

看网上说的这种写法:出处https://blog.csdn.net/yishichangan1/article/details/51850048

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <!-- 连框颜色值 -->
    <item>
        <shape>
            <solid android:color="#000000" />
        </shape>
    </item>
   <!-- 主体背景颜色值 --><!-- 此处定义只有上下两边有边框 高度为1像素-->
    <item
    android:bottom="1dp"
    android:top="1dp">
    <!--边框里面背景颜色 白色-->
        <shape>
            <solid android:color="#ffffff" />
        </shape>
    </item>
</layer-list>

不知道为什么,我使用起来背景色永远是白色,改不动。。。有知道麻烦留言告诉我。
我用了另一种方法:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:left="-1dp"
        android:right="-1dp">
        <shape>
            <stroke
                android:width="1dp"
                android:color="#ebefeb" />
        </shape>
    </item>

</layer-list>

就是将需要去掉的边写成负值。
同理,只要上边的话:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:left="-1dp"
        android:right="-1dp"
        android:bottom="-1dp">
        <shape>
            <stroke
                android:width="1dp"
                android:color="#ebefeb" />
        </shape>
    </item>

</layer-list>

————————-补充————————————————
如果需要加背景色:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <!-- This is the line -->
    <item
        android:left="-1dp"
        android:right="-1dp">
        <shape>
            <stroke
                android:width="1dp"
                android:color="#ebefeb" />
        </shape>
    </item>

    <item>
        <shape>
            <solid android:color="#1AFFFFFF" />
        </shape>
    </item>
</layer-list>

猜你喜欢

转载自blog.csdn.net/qq_38969990/article/details/79986260