Adi*_*mro 48
在你想要的dawable文件夹名中创建一个xml文件 gradient_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#000"
android:endColor="#fff"
android:angle="90"
/>
</shape>
Run Code Online (Sandbox Code Playgroud)
并将其设置为您的背景View.
android:background="@drawable/gradient_bg"
Run Code Online (Sandbox Code Playgroud)
要么
setBackgroundResource(R.drawable.gradient_bg);
Run Code Online (Sandbox Code Playgroud)
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:angle="90"
android:type="linear"
android:startColor="#FFFFFF"
android:endColor="#000000" />
</shape>
Run Code Online (Sandbox Code Playgroud)
这里如果你设置角度,270开始颜色将出现在底部,如果你设置角度,90它的顶部颜色将被反转