Sammy
Sammy

Reputation: 181

custom border for ImageView

I want to remove the peach solid color from interior portion and just want it at the border of top, left and right. The bottom color red is fine. I searched everywhere but they only suggested to use solid to overlap the whole red border.

XML Code

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <!-- Draw a 2dp width border around shape -->
            <stroke
                android:color="#ff1e0c"
                android:width="2dp"
                />
        </shape>
    </item>
    <!-- Overlap the left, top and right border using background color  -->
    <item
        android:bottom="2dp"
        >
        <shape android:shape="rectangle">
            <solid android:color="#fffbce"/>
        </shape>
    </item>

</layer-list>

present look

Upvotes: 1

Views: 226

Answers (1)

Amit Vaghela
Amit Vaghela

Reputation: 22965

try this solution,

<?xml version="1.0" encoding="utf-8"?>

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- This is the line -->
    <item android:bottom="1dp">
        <shape>
            <solid android:color="#00000000" />
            <stroke
                android:width="1dp"
                android:color="#FF0000" />
        </shape>
    </item>
    <item
        android:bottom="-1dp"
        android:left="0dp"
        android:top="0dp">
        <shape>
            <solid android:color="#00000000" />
            <stroke
                android:width="1dp"
                android:color="#000000" />
        </shape>
    </item>


</layer-list>

Upvotes: 1

Related Questions