界面背景渐变色

Android ui背景如果希望设置成渐图案,可以有两种方法,第一种就是ps一下作为backgroundimage。下面介绍下android中提供的第二种方法

1、在res/drawable下添加gradient.xml文件定义渐变色样式

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
	<gradient android:startColor="#CECEFF" 
		android:endColor="#2828FF" 
		android:angle="45"/> 
</shape> 
 shape是用来定义形状的

gradient定义该形状里面为渐变色填充

startColor起始颜色

endColor结束颜色

angle表示方向角度。当angle=0时,渐变色是从左向右。 然后逆时针方向转,当angle=90时为从下往上。

 

2、在layout具体的设置中调用

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="@drawable/gradient"> 

</LinearLayout> 
 

当然最后需要在Activity的OnCreate中setContentView

 

附录:

颜色表http://tool.webmasterhome.cn/html-color.asp

 

你可能感兴趣的:(界面)