在drawable文件夾下新建btn_shape.xml文件:
1 <?xml version="1.0" encoding="utf-8"?> 2 <shape xmlns:android="http://schemas.android.com/apk/res/android" 3 android:shape="rectangle"> 4 <solid android:color="#ffffff"/> 5 <corners 6 android:topLeftRadius="8dip" 7 android:topRightRadius="8dip 8 android:bottomLeftRadius="8dip" 9 android:bottomRightRadius="8dip"/> 10 </shape>
先解釋一下上面的代碼:
1.shape用於定義形狀,有四種形狀(矩形rectangle| 橢圓oval | 直線line | 圓形ring)。
2.solid用於設置填充形狀的顏色。
3.corners用於創建圓角(只用於形狀是矩形)。

topLeftRadius、topRightRadius、bottomLeftRadius、bottomRightRadius分別設置左上,右上,左下,右下圓角的半徑。
使用方法:
android:background="@drawable/btn_shape"
1 <Button 2 android:layout_width="wrap_content" 3 android:layout_height="wrap_content" 4 android:id="@+id/button" 5 android:background="@drawable/btn_shape" 6 />
效果圖:
1 參考網址: 2 http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape
