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" />

這是一個按鈕的背景
在這裏插入圖片描述

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