Drawable的使用——ShapeDrawable

ShapeDrawable在开发过程中经常用到,可以理解为通过颜色来构造的图片,可以是纯色的,也可以是渐变色的。
对应的是标签,由于这个经常用到,这里只展示个简单的效果

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners
        android:bottomLeftRadius="2dp"
        android:bottomRightRadius="8dp"
        android:topLeftRadius="5dp"
        android:topRightRadius="6dp" />
    <gradient
        android:angle="45"
        android:centerColor="@color/colorPrimary"
        android:endColor="@color/lightGreen"
        android:startColor="@color/lightGreen" />
    <stroke
        android:color="@color/black"
        android:dashWidth="5dp"
        android:dashGap="1dp" />

</shape>
    <Button
                android:id="@+id/btn_reverse"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/bg_shape_drawable"
                android:text="Reverse"
                android:textColor="@color/white" />

这是一个按钮的背景
在这里插入图片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章