Android背景颜色渐变可以通过在res/drawable里定义一个xml文件(xml文件名称可根据个人定义):
一、color_gradient.xml代码:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="0"
android:startColor="#95C5F3"
android:centerColor="#FFFFFF"
android:endColor="#9BDD52"
android:type="linear"/>
</shape>
1、android:angle 渐变方向角度
2、android:startColor 开始颜色
3、android:centerColor 中间颜色
4、android:endColor 结束颜色
5、android:type 渐变类型,线性linear
二、在你想要实现的界面中使用:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ColorActivity"
android:orientation="vertical"
android:background="@drawable/color_gradient">
</LinearLayout>