展会信息港展会大全

Android背景渐变色(shape,gradient)
来源:互联网   发布日期:2015-10-02 16:11:34   浏览:1167次  

导读:Android设置背景色可以通过在res/drawable里定义一个xml,如下:?xml version=1.0 encoding=utf-8?shape xmlns:android=http://schemas.android.com/apk/res/androidgradientandroid:startColor=#......

Android设置背景色可以通过在res/drawable里定义一个xml,如下:

<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android">

<gradient

android:startColor="#FFF"

android:endColor="#000"

android:angle="45" />

</shape>

shape是用来定义形状的,gradient定义该形状里面为渐变色填充,startColor起始颜色,endColor结束颜色,angle表示方向角度。当angle=0时,渐变色是从左向右。 然后逆时针方向转,当angle=90时为从下往上。

实现过程:

第一步:

res/drawable/background_login.xml

<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android">

<gradient

android:startColor="#FFF"

android:endColor="#000"

android:angle="45" />

</shape>

第二步:

res/layout/login.xml

<?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/background_login">

</LinearLayout>

第三步:

import android.app.Activity;

import android.os.Bundle;

public class LoginActivity extends Activity {

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.login);

}

}

效果图:

赞助本站

人工智能实验室

相关热词: shape gradient 背景 渐变色

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港