android——背景颜色渐变(梯度变化)

首先在drawable文件夹下面新建一个xml文件,起名为bgcolor.xml。

代码如下:

<?xml version="1.0" encoding="utf-8"?>

 <shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient
        android:startColor="#000000"
        android:endColor="#FFFFFF"
        android:angle="90"
        />
 </shape>

然后,在需要使用到该背景的地方,加上

    android:background="@drawable/background_color"

就这样搞定了。

对了。angle设置的角度。该角度必须是45的倍数。

效果如下

原文地址:https://www.cnblogs.com/shoneworn/p/5035238.html