背景色渐变可以通过在res/drawable中定义一个XML文件实现,gradient.xml的代码如下:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#FFFFFF"
android:endColor="#000000"
android:angle="45"/>
</shape>
<?xml version="1.0" encoding="utf-8"?>< shape xmlns:android="http://schemas.android.com/apk/res/android"> <gradient android:startColor="#FFFFFF" android:endColor="#000000" android:angle="45"/>< /shape>
其中,shape是用来定义形状的,gradient定义该形状里面为渐变色填充,startColor起始颜色,endColor结束颜色,angle表示方向角度。当angle=0时,渐变色是从左向右。 然后逆时针方向转,当angle=45时为从左下到右上,当angle=90时为从下往上。