XML Color for the area outside the rectangular curved edges

I am creating a rectangle for the RelativeLayout background and wondered how I could make the area outside the rounded edges of this rectangle also darker_grey. Currently, only inside 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> 
+5
source share
2 answers

You can do this by switching to layer-list drawable and drawing your shape on top of the solid color, for example:

 <?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> 
+7
source

Another way to implement a background color for any view using a form:

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

Please decide the width and height of the view based on your requirements.

It will look like :

enter image description here

+2
source

Source: https://habr.com/ru/post/1274875/


All Articles