View设置背景渐变色(shape,gradient)
来源:互联网 发布:google浏览器 for mac 编辑:程序博客网 时间:2024/05/01 09:01
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
}
效果图:
1 0
- View设置背景渐变色(shape,gradient)
- 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)
- Java强引用、 软引用、 弱引用、虚引用
- 文本挖掘--将分词之后的文档转化为结构化的数据
- 彻底解决错误Duplicate files copied in APK xxx/xxx/xxx/LICENSE.txt
- jsp中使用s:if比较时间
- 类属性复制实现
- View设置背景渐变色(shape,gradient)
- Java泛型(一) 泛型的概念 基础
- Android仿美团团购详情页下拉图片放大效果,简单可直接用在项目中
- cf 540 C Ice Cave
- 关于delete和deletelater的问题
- Java并发编程:线程池的使用
- Objective-C 12 类别Category
- iOS集成极光推送,绕过一些坑
- Storm+Kafka集成