制作胶囊状按钮
核心是采用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" />
半个胶囊效果及实现方式

<?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>
网友评论