Rounded corner for textview in android
Create
rounded_corner.xml
in thedrawable
folder and add the following content,<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" > <stroke android:width="1dp" android:color="@color/common_border_color" /> <solid android:color="#ffffff" /> <padding android:left="1dp" android:right="1dp" android:bottom="1dp" android:top="1dp" /> <corners android:radius="5dp" /></shape>
Set this drawable in the
TextView
background property like so:android:background="@drawable/rounded_corner"
I hope this is useful for you.
Beside radius
, there are some property to round corner like topRightRadius
, topLeftRadius
, bottomRightRadius
, bottomLeftRadius
Example TextView
with red
border with corner and gray
background
bg_rounded.xml (in the drawables folder)
<shape xmlns:android="http://schemas.android.com/apk/res/android"> <stroke android:width="10dp" android:color="#f00" /> <solid android:color="#aaa" /> <corners android:radius="5dp" android:topRightRadius="100dp" /></shape>
TextView
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/bg_rounded" android:text="Text" android:padding="20dp" android:layout_margin="10dp" />
Result
Since your top level view already has android:background property set, you can use a <layer-list>
(link) to create a new XML drawable that combines both your old background and your new rounded corners background.
Each <item>
element in the list is drawn over the next, so the last item in the list is the one that ends up on top.
<?xml version="1.0" encoding="utf-8"?><layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item> <bitmap android:src="@drawable/mydialogbox" /> </item> <item> <shape> <stroke android:width="1dp" android:color="@color/common_border_color" /> <solid android:color="#ffffff" /> <padding android:left="1dp" android:right="1dp" android:top="1dp" /> <corners android:radius="5dp" /> </shape> </item></layer-list>