How to set a shape's background in xml? How to set a shape's background in xml? android android

How to set a shape's background in xml?


I think a layer-list might help you:

<?xml version="1.0" encoding="utf-8"?><layer-list xmlns:android="http://schemas.android.com/apk/res/android" >    <item>        <shape android:shape="rectangle" >            <solid android:color="#ffffff" />        </shape>    </item>    <item>        <shape            android:innerRadiusRatio="4"            android:shape="ring"            android:thicknessRatio="9"            android:useLevel="false" >            <solid android:color="#FF0000" />            <size                android:height="48dip"                android:width="48dip" />        </shape>    </item></layer-list>


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


I am just adding helpful research as an answer. Let us suppose you have a shape as the answer described by @GeneBo and you are looking forward to re-using that shape but with a different solid color. So all you need to do in your widget is:

android:background="@drawable/your_shape_to_reuse"android:backgroundTint="@color/new_background_color_you_need"