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>
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 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>
</item>
</layer-list>
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With