Android如何設置圓角按鈕


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.在布局文件中調用。

  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>  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM