android 形状中超过 2 条边的边框

Borders for more than 2 sides in android shape

我已经使用代码

为自定义形状的左侧和顶部添加了边框
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="#787878" />

        </shape>
    </item>

    <item android:left="1dp" android:top="1dp">
        <shape android:shape="rectangle">
            <solid android:color="#e4e4e4" />
        </shape>
    </item>

</layer-list>

现在我想为右侧和底部添加不同的边框颜色。但是,当我将代码更新为

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="#787878" />
        </shape>
    </item>

    <item android:left="1dp" android:top="1dp">
        <shape android:shape="rectangle">
            <solid android:color="#e4e4e4" />
        </shape>
    </item>

    <item android:right="1dp">
        <shape android:shape="rectangle">
            <solid android:color="#e4e4e4" />
        </shape>
    </item>

</layer-list>

none 的边框是可见的,当我应该在 3 边获得边框时。我做错了什么?

这里你需要像这样给每个项目添加填充:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

<item>
    <shape android:shape="rectangle" >
        <padding
            android:left="2dp"
            android:top="2dp" />

        <solid android:color="@android:color/holo_red_dark" />
    </shape>
</item>
<item>
    <shape android:shape="rectangle" >
        <padding android:right="2dp" />

        <solid android:color="@android:color/holo_blue_dark" />
    </shape>
</item>
<item>
    <shape android:shape="rectangle" >
        <padding android:bottom="2dp" />

        <solid android:color="@android:color/white" />
    </shape>
</item>
<item>
    <shape android:shape="rectangle" >
        <solid android:color="@android:color/holo_green_light" />
    </shape>
</item>

希望真的有帮助!