Is it possible to draw a shape in xml, and use a png as the background to that shape? I already have the shape (it's a square with rounded corners), and i would like to put a background to that square.
The <shape> element is where the shape of your drawable is defined and all its nested elements are defined. The android:shape attribute can hold four values: rectangle , oval , ring , or line . If you do not specify a value, it will be a rectangle by default.
A drawable resource is a general concept for a graphic that can be drawn to the screen and which you can retrieve with APIs such as getDrawable(int) or apply to another XML resource with attributes such as android:drawable and android:icon . There are several different types of drawables: Bitmap File.
Yes you can use any shape file as background for any view. This sample create rounded background with white color and black border around the shape.
Sample :
rounded_corner.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <corners android:bottomLeftRadius="10dp" android:bottomRightRadius="10dp" android:topLeftRadius="10dp" android:topRightRadius="10dp" /> <stroke android:width="0.5dp" android:color="@color/color_grey" /> <solid android:color="@color/color_white" /> </shape>
u can use this as,
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="center_horizontal" android:background="@drawable/rounded_corner" android:orientation="vertical" >
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