The rounded border of the control can make your App look more beautiful. In fact, it is easy to implement.
(Original address: http://blog.csdn.net/vector_yi/article/details/24463025)
Take a gray Button with a rounded border as an example:
1. Create a ShapeDrawable as the background and create a button_rounded_background.xml file in the drawable directory:
<shape xmlns:android = "http://schemas.android.com/apk/res/android" android:shape= "rectangle" > <solid android:color= "#AAAAAA" /> <corners android:radius= "15dp" /></shape>
See the name, in addition to the <solid/>, <corners/> label, <shape/> also supports a lot of different functional labels, for more information, please go to the Android official documentation: http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape
2. Apply ShapeDrawablemain. xml to the Button:
<RelativeLayout xmlns:android = "http://schemas.android.com/apk/res/android" android:layout_width= "fill_parent" android:layout_height= "fill_parent" android:gravity= "center" > <Button android:id ="@+id/button" android:layout_width ="wrap_content" android:layout_height ="wrap_content" android:background ="@drawable/button_rounded_background" android:padding ="10dp" android:text ="@string/hello" android:textColor ="#000000" /></RelativeLayout>
Now a Button with a rounded border has been built.
ShapeDrawable can be used not only in the Button, but also with all controls with background, such as items in ListView.