制作膠囊狀按鈕
核心是采用shape來進行繪制年栓。
可以作為View流纹、TextView糜烹、各種Layout的背景(background)屬性,但是不能作為Button的背景漱凝。
樣例:
代碼:shape_capsule_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:bottomLeftRadius="30dp"
android:bottomRightRadius="30dp"
android:topLeftRadius="30dp"
android:topRightRadius="30dp" />
<solid android:color="#cdcdcd" />
</shape>
使用:
<TextView
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/shape_capsule_bg"
android:gravity="center"
android:text="獲取驗證碼"
android:textColor="#ffffff"
android:textSize="16sp" />
半個膠囊效果及實現(xiàn)方式
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<corners
android:bottomLeftRadius="30dp"
android:bottomRightRadius="0dp"
android:topLeftRadius="30dp"
android:topRightRadius="0dp" />
<solid android:color="#cdcdcd" />
</shape>