定义一个shapDrawable
<span style="font-size:18px;background-color: rgb(255, 255, 255);"><?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- 定义填充的颜色-->
<solid android:color="@color/red"/>
<!-- 定义距离内容的长度-->
<padding android:bottom="7dp"
android:left="7dp"
android:right="7dp"
android:top="7dp"/>
<!-- 边框的长度和颜色-->
<stroke android:color="@color/blue"
android:width="3dip"/>
<!-- 四角的弧度-->
<corners android:radius="3dp"/>
</shape></span>
<span style="font-size:18px;background-color: rgb(255, 255, 255);">需要使用的时候设置为某个组件的背景就可以了,</span>
<span style="background-color: rgb(255, 255, 255);"> <TextView
android:id="@+id/text_view_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world"
android:background="@drawable/shape_drawable"/></span>
定义渐变颜色:
<gradient android:angle="45"
android:startColor="@color/yellow"
android:endColor="@color/pink"/>
然后效果是这样的: