Android背景渐变色(shape,gradient)
来源:互联网 发布:web前端评测软件 编辑:程序博客网 时间:2024/05/22 01:45
From:http://l62s.iteye.com/blog/1659433
Android设置背景色可以通过在res/drawable里定义一个xml,如下:
[代码]xml代码:
1
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
2
<
shape
xmlns:android
=
"http://schemas.android.com/apk/res/android"
>
3
<
gradient
4
android:startColor
=
"#FFF"
5
android:endColor
=
"#000"
6
android:angle
=
"45"
/>
7
</
shape
>
shape是用来定义形状的,gradient定义该形状里面为渐变色填充,startColor起始颜色,endColor结束颜色,angle表示方向角度。当angle=0时,渐变色是从左向右。 然后逆时针方向转,当angle=90时为从下往上。
实现过程:
第一步:
res/drawable/background_login.xml
[代码]xml代码:
1
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
2
<
shape
xmlns:android
=
"http://schemas.android.com/apk/res/android"
>
3
<
gradient
4
android:startColor
=
"#FFF"
5
android:endColor
=
"#000"
6
android:angle
=
"45"
/>
7
</
shape
>
第二步:
res/layout/login.xml
[代码]xml代码:
1
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
2
<
LinearLayout
xmlns:android
=
"http://schemas.android.com/apk/res/android"
3
android:orientation
=
"vertical"
4
android:layout_width
=
"fill_parent"
5
android:layout_height
=
"fill_parent"
6
android:background
=
"@drawable/background_login"
>
7
</
LinearLayout
>
第三步:
[代码]java代码:
01
import
android.app.Activity;
02
import
android.os.Bundle;
03
04
public
class
LoginActivity
extends
Activity {
05
@Override
06
public
void
onCreate(Bundle savedInstanceState) {
07
super
.onCreate(savedInstanceState);
08
setContentView(R.layout.login);
09
}
10
}
效果图:
0 0
- 1. android 背景渐变色(shape,gradient)
- android 背景渐变色(shape,gradient)
- android 背景渐变色(shape,gradient)
- android 背景渐变色(shape,gradient)
- android 背景渐变色(shape,gradient)
- android 背景渐变色(shape,gradient)
- android 背景渐变色(shape,gradient)
- android 背景渐变色(shape,gradient)
- android 背景渐变色(shape,gradient)
- Android背景渐变色(shape,gradient)
- Android背景渐变色(shape,gradient)
- Android背景渐变色(shape,gradient)
- Android背景渐变色(shape,gradient)
- Android背景渐变色(shape,gradient)
- Android背景渐变色(shape,gradient)
- Android背景渐变色(shape,gradient)
- Android背景渐变色(shape,gradient)
- Android背景渐变色(shape,gradient)
- ASP.NET中如何使用lock
- RabbitMQ之队列与消息持久化
- UI笔记_事件处理
- 黑马程序员---java之IO流(二)
- 【OJ】---Y---输入输出,私有继承
- Android背景渐变色(shape,gradient)
- CSS3 Media Query实现响应式Web设计(针对不同移动设备宽度)
- 总有一种正能量触动你的心灵,读刘丁宁的一封信
- webservice CXF整合spring服务端测试并生成wsdl文件
- spring的PropertyPlaceholderConfigurer和PropertyOverrideConfigurer
- Command terminated by signal 11
- android的activity栈管理
- 2014-06-27 日志
- 今天看到有人要用matlab作数据简单拟合;用gnuplot+CTeX试了一下效果