Eclipse中Button如何设置圆角

来源:互联网 发布:广州聚焦网络 编辑:程序博客网 时间:2024/06/07 02:46

1.res目录下的drawable目录下新建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.   
  5.     <!-- 填充的颜色 -->  
  6.     <solid android:color="#FF065E8D" />  
  7.   
  8.     <!-- 设置按钮的四个角为弧形 -->  
  9.     <!-- android:radius 弧形的半径 -->  
  10.     <corners android:radius="15dip" />  
  11.   
  12.     <!-- padding:Button里面的文字与Button边界的间隔 -->  
  13.     <padding  
  14.         android:bottom="10dp"  
  15.         android:left="10dp"  
  16.         android:right="10dp"  
  17.         android:top="10dp" />  
  18. </shape>  

2.在布局文件中调用。

[html] view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     android:orientation="vertical" >  
  6.   
  7.     <Button  
  8.         android:id="@+id/roundButton"  
  9.         android:layout_width="wrap_content"  
  10.         android:layout_height="wrap_content"  
  11.         android:background="@drawable/shape"  
  12.         android:text="圆角按钮" />  
  13. </LinearLayout> 
原创粉丝点击