Android學習——Button填充顏色及實現圓角


 在drawable下新建文件夾bt_shape.xml,如下:

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <shape xmlns:android="http://schemas.android.com/apk/res/android">
 3 
 4     android:shape="rectangle">                      //shape用於定義形狀,有四種形狀(矩形rectangle| 橢圓oval | 直線line | 圓形ring)
 5     <solid android:color="#00f"/>                   //solid用於設置填充形狀的顏色
 6     <corners                                        //corners用於創建圓角(只用於形狀是矩形)
 7         android:topLeftRadius="8dip" 
 8         android:topRightRadius="8dip"
 9         android:bottomLeftRadius="8dip"
10         android:bottomRightRadius="8dip"/>
11 </shape>

在activity_main.xml下使用:

1     <Button
2         android:id="@+id/button"
3         android:layout_width="match_parent"
4         android:layout_height="wrap_content"
5         android:background="@drawable/bt_shape"     //引用
6         android:text="確認"
7         android:textColor="#fff"
8         />

實現效果如下:


免責聲明!

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



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