Paradox
Paradox

Reputation: 4566

XML Color for area outside rectangle's curved edges

I am making a rectangle for the background of a RelativeLayout and was wondering how I could make the area outside of the rounded edges of this rectangle to also be darker_grey. Currently, only the inside of this rectangle is darker_grey

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
    <solid android:color="@android:color/darker_gray" />
    <stroke android:width="1dip" android:color="@android:color/black"/>
    <corners android:radius="20dp" />
</shape>

Upvotes: 4

Views: 1757

Answers (2)

Logan Pickup
Logan Pickup

Reputation: 2374

You can do it by switching to a layer-list drawable, and layering your shape on top of a solid colour, like so:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <color android:color="@android:color/darker_gray" />
    </item>
    <item>
        <shape android:shape="rectangle">
            <solid android:color="@android:color/darker_gray" />
            <stroke android:width="1dip" android:color="@android:color/black"/>
            <corners android:radius="20dp" />
        </shape>
    </item>
</layer-list>

Upvotes: 9

Jitesh Mohite
Jitesh Mohite

Reputation: 34210

Another way to implement background color to any view using shape:

<ImageView
        android:layout_width="200dp" 
        android:layout_height="200dp"
        android:background="@android:color/darker_gray"
        android:src="@drawable/shape"/>

Please decide view width and height based on your requirement.

It will look like:

enter image description here

Upvotes: 1

Related Questions