在drawable文件夹下新建btn_shape.xml文件:

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <shape xmlns:andro
 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用于创建圆角(只用于形状是矩形)。

                 Android学习之——实现圆角Button

    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:
5         android:background="@drawable/btn_shape"
6         />

  效果图:

         Android学习之——实现圆角Button

 

1 参考网址:
2 http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-07
  • 2022-12-23
  • 2021-10-01
猜你喜欢
  • 2022-12-23
  • 2021-09-08
  • 2022-12-23
  • 2022-01-30
  • 2021-09-13
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案