On the android website, there is a section about color drawables. Defining these drawables in xml looks like this:
<resources> <drawable name="solid_red">#f00</drawable> <drawable name="solid_blue">#0000ff</drawable> <drawable name="solid_green">#f0f0</drawable> </resources>
In the java api, they have thr following method to define rounded corners:
setCornerRadius(float radius)
Is there a way to set the rounded corners in the xml?
To do that right click on drawable (under resources), choose New, choose Drawable Resource File. Name the resource rounded_blue_border and make the root element shape. We will use the attributes stroke, corners and padding. The stroke determines the width and color of the border.
Use app:drawableTint="@color/yourColor" in the xml instade android:drawableTint="@color/yourColor" . It has the backward compatibility.
xml file and add an attribute to that TextView, for which you want to add rounded corners. The attribute is android: background=”@drawable/rounded_corner_view”.
Use the <shape>
tag to create a drawable in XML with rounded corners. (You can do other stuff with the shape tag like define a color gradient as well).
Here's a copy of a XML file I'm using in one of my apps to create a drawable with a white background, black border and rounded corners:
<?xml version="1.0" encoding="UTF-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#ffffffff"/> <stroke android:width="3dp" android:color="#ff000000" /> <padding android:left="1dp" android:top="1dp" android:right="1dp" android:bottom="1dp" /> <corners android:radius="7dp" /> </shape>
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