先上效果圖:
具體步驟:
1.在drawable文件夾下新建一個xml文件。
2.在裏面填上以下內容:
<?xml version="1.0" encoding="utf-8"?>
<!--自定義的控件圓角背景-->
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/white"/>
<padding android:top="10px" android:bottom="10px"/>
<corners android:radius="50px"/>
<stroke android:width="1px" android:color="#f08200"/>
</shape>
3.在xml文件中使用:
4.註釋:
corners ----------圓角
gradient ----------漸變
padding ----------內容離邊界距離
size ------------大小
solid ----------填充顏色
stroke ----------描邊
注意的是corners的屬性bottomLeftRadius爲右下角、bottomRightRadius爲左下角
shape製作虛線
沒有dashGap屬性則爲實線
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line" >
<stroke
android:dashGap="3dp"
android:dashWidth="8dp"
android:width="1dp"
android:color="#63a219" />
<size android:height="1dp" />
</shape>
4.0以上虛線變實線在xml文件中增加:
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/xuxian"
android:layerType="software" />
shape製作漸變
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:angle="270.0"
android:endColor="#ffffff"
android:startColor="#000000" />
</shape>
參考:http://www.cnblogs.com/tinyphp/p/3829895.html