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);
}
}

Android背景渐变色(shape,gradient)的更多相关文章

  1. Android背景渐变色效果

    Android设置背景色可以通过在res/drawable里定义一个xml,如下: [代码]xml代码: 1 <?xml version="1.0" encoding=&qu ...

  2. Android中使用shape实现EditText圆角

    之前看到手机上的百度editText控件是圆角的就尝试做了一下,看了看相关的文章. 因为代码少,看看就知道了.所以下面我就直接贴上代码供大家参考,有其他的好方法记得分享哦~ 整个代码不涉及JAVA代码 ...

  3. Android中使用shape来定义控件

    本文章转接于:http://kofi1122.blog.51cto.com/2815761/521605 Android中常常使用shape来定义控件的一些显示属性,今天看了一些shape的使用,对s ...

  4. Android Selector 与 Shape 基本用法

    分类: Android2011-07-19 11:07 7513人阅读 评论(4) 收藏 举报 androidencodingbutton测试c 1:Selector drawable的item中可以 ...

  5. Android UI(一)Layout 背景局部Shape圆角设计

    Jeff Lee blog:   http://www.cnblogs.com/Alandre/  (泥沙砖瓦浆木匠),retain the url when reproduced ! Thanks ...

  6. Android (shape,gradient)使用总结

    设置背景色可以通过在res/drawable里定义一个xml,如下: <?xml version="1.0" encoding="utf-8"?> ...

  7. android 开发:shape和selector和layer-list的(详细说明)

    目录(?)[+] Shape 简介 使用的方法 属性 Selector 简介 使用的方法 layer-list 简介 例子 最后   <shape>和<selector>在An ...

  8. android背景选择器selector用法汇总

    一.创建xml文件,位置:drawable/xxx.xml,同目录下记得要放相关图片 <?xml version="1.0" encoding="utf-8&quo ...

  9. android——背景颜色渐变(梯度变化)

    首先在drawable文件夹下面新建一个xml文件,起名为bgcolor.xml. 代码如下: <?xml version="1.0" encoding="utf- ...

随机推荐

  1. LeetCode 169. Majority Element

    Given an array of size n, find the majority element. The majority element is the element that appear ...

  2. js代码生成form,解决mvc的url参数过长问题

    在MVC项目中,通常下载的文件的简单方式是直接采用 location.href+查询参数方式. var searchParams = { studentName: $("#StudentNa ...

  3. js解决IE不支持数组的indexOf()方法

    if (!Array.indexOf) {                                    Array.indexOf = function (obj) {            ...

  4. python 脚本中使用了第三方openpyxl 打包程序运行提示ImportError:cannot import name __version__

    最近写了一个脚本,脚本中使用了第三方openpyxl(openpyxl是使用 pip install openpyxl 下载的),先是使用py2exe打包程序,打包过程中提示很多文件没有包含,在没有仔 ...

  5. 数据库——DQL(语句查询)

    查询的基本结构: 概念: 查询(DQL)是数据库中最为常用和复杂的一种SQL结构,学会编写查询SQL是程序员必须具备的能力. 要从数据库中查询数据,我们要使用SQL的SELECT语句.标准SELECT ...

  6. zookeeper 节点的移动与删除

    package com.zhengmo.test; import java.util.List; import org.apache.zookeeper.CreateMode; import org. ...

  7. 利用IDL将一个txt文档拆分为多个

    测试.txt文档,每47行的格式相同,通过代码每47行存为一个txt,txt文档命名为其第一行数据. 代码如下: file='G:\data\测试.txt' openr,lun,file,/Get_L ...

  8. 【leetcode】 Remove Duplicates from Sorted List

    Given a sorted linked list, delete all duplicates such that each element appear only once. For examp ...

  9. mongoDB学习记录---PHP扩展的find返回值

    最近的一个项目中用到了MongoDB,主要是使用MongoDB的PHP扩展.MongoDB的扩展中用于一个用于查询的方法是find().下面针对在理解MongoDB扩展的find()方法中做的实验做个 ...

  10. 基本变换(读书笔记5 --- Real-Time rendering)

    刚体变换 即变换不改变了被变换顶点之间的距离,以及偏手性(不会让左右手坐标系颠倒). 下面的平移变换.旋转变换即属于刚体变换 平移 从一个位置变到另一个位置可以用平移矩阵T来表示,这个矩阵将一个实体变 ...