1. Add a resource file
// res/drawable/bg_btn_round_corner.xml<?xml version= "1.0" encoding= "Utf-8"? ><shape xmlns:android= "Http://schemas.android.com/apk/res/android" android:shape= "Rectangle" > <corners Android : radius= "16DP"/> <solid android:color= "#ff7777"/> <stroke android:width= "2DP" Android:color= "#0000ff"/> <gradient android:endcolor= "#ff7777" Android:startcolor= "#ff0000"/></shape>
The resulting preview is shown below:
Because the gradient property is also used above, the solid property does not work. If the interior is solid color, you can configure only the solid property. Gradient represents the gradient effect.
2. Use this resource in the layout file, and use the same method as the picture resource.
<button android:layout_width= " android:layout_height" = "60DP" android: Background= "@drawable/bg_btn_round_corner" android:text= "Hello" android:textsize= "18sp"/>
The result is this.
Android Set Rounded Rectangle