在drawable目录下创建xml
1.上下渐变效果图
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient android:startColor="#1215dc"
android:endColor="#8ab4f2"
android:angle="90"/>
</shape>
2.左右渐变效果图
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#1215dc"
android:endColor="#8ab4f2"
android:angle="180"/>
</shape>
3.倾斜渐变效果图
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#1215dc"
android:centerColor="#70a6f5"
android:endColor="#1215dc"
android:angle="135"/>
</shape>
4.字段的属性
- startColor:头部颜色
- endColor:尾部颜色
- centerColor:中部颜色
- angle:倾斜角度
5.使用
直接在想要设置渐变色的布局控件下加入
android:background="@drawable/shape_corner_lan"//你自己的xml文件名字
搭配圆角布局简直是绝配
不会圆角布局的可以看我之前的文章