drawable右键新建Drawable resource file
设置圆角和边框
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!--设置背景色-->
<solid android:color="#ffffff"/>
<!--设置圆角-->
<corners android:radius="4dp"/>
<!--设置边框线的宽度和颜色-->
<stroke android:width="1dp" android:color="#FECB51" />
</shape>
设置渐变
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!--设置渐变颜色-->
<gradient
android:endColor="#4955C6"
android:startColor="#343FA1"
android:type="linear"
android:angle="0"/>
</shape>
当angle=0时,渐变色是从左向右。 然后逆时针方向转,当angle=90时为从下往上。
Button中设置background属性为该xml文件
两个shape一起用,一个7dp高的渐变,一个背景色
<layer-list xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:height="7dp"
tools:ignore="UnusedAttribute">
<shape android:shape="rectangle">
<!--<solid android:color="#8c9edc"/>-->
<size android:height="7dp"/>
<gradient
android:angle="90"
android:endColor="#ffffff"
android:startColor="#e4e2e2"/>
</shape>
</item>
<item android:top="7dp">
<shape android:shape="rectangle">
<solid android:color="#ffffff"/>
</shape>
</item>
</layer-list>
设置阴影效果的第二种方法
控件设置elevation属性或者translationZ,必须同时设置background才能有效果
android:elevation="" android:translationZ=""
Z=elevation+ translationZ