在res/drawable里定义一个toolbar_bg.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="0"
android:startColor="#f89e07"
android:centerColor="#ee5511"
android:endColor="#e40b1b"
android:type="linear" />
</shape>
android:angle 渐变的角度,必须是45的倍数
android:startColor 开始颜色
android:centerColor 中间颜色
android:endColor 结束颜色
android:type=”linear” 线性渐变
然后直接调用就可以了 android:background=“@drawable/toolbar_bg”
0 : 从左到右
45:从左下角到右上角
90:从下向上
135:从右下到左上
180:从右到左
225:从右上到左下
270:从上到下
325:从左上到右下