how to make stroke for 3 sides for a shape in android?

Viewed 27005

I am using a stroke to make a colored border to a shape in xml layout in android .

Can I make the stroke for only 3 edges ( left,top,bottom) the right NO ?

4 Answers

Using @Mopper answer, you can like that too.

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape>
            <solid android:color="#ff0000" />
        </shape>
    </item>
    <item
        android:bottom="3dp"
        android:left="3dp"
        android:right="0dp"
        android:top="3dp">
        <shape>
            <solid android:color="#00ff00" />
        </shape>
    </item>
</layer-list>

Here's my solution, which works if you want transparent or semi-transparent background colors.

<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <inset xmlns:android="http://schemas.android.com/apk/res/android"
            android:insetLeft="-1dp"
            >
        <shape xmlns:android="http://schemas.android.com/apk/res/android">
            <stroke
                android:color="#c45b5b5b"
                android:width="1dp"/>
            <corners
                android:bottomLeftRadius="0dp"
                android:bottomRightRadius="5dp"
                android:topLeftRadius="0dp"
                android:topRightRadius="5dp"
                />
        </shape>
        </inset>
    </item>
    <item
        android:top="1dp"
        android:right="1dp"
        android:bottom="1dp"
        android:left="0dp">
        <shape xmlns:android="http://schemas.android.com/apk/res/android">
            <solid android:color="@color/infoBox_Background"/>
            <corners
                android:bottomLeftRadius="0dp"
                android:bottomRightRadius="5dp"
                android:topLeftRadius="0dp"
                android:topRightRadius="5dp"
                />
        </shape>
    </item>
</layer-list>
Related