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. SQL Server选项综述

    I. 基本概念 SQL Server中的选项根据其作用范围分为如下几类: 实例选项 —— 在数据库实例范围内有效,通过 sp_configure 存储过程进行配置. 数据库选项 —— 在数据库范围内有 ...

  2. 在 Typescript 2.0 中使用 @types 类型定义

    在 Typescript 2.0 中使用 @type 类型定义 基于 Typescript 开发的时候,很麻烦的一个问题就是类型定义.导致在编译的时候,经常会看到一连串的找不到类型的提示.解决的方式经 ...

  3. Delegate, Method as Parameter.

    代理, 将方法作为另一方法的参数. 类似C里面的函数指针. using System; using System.Windows.Forms; using System.Threading; name ...

  4. MySQL Workbench “Error Code: 1175” 的解决方法

    转自:http://www.linuxidc.com/Linux/2012-04/59333.htm 当用MySQL Workbench进行数据库的批量更新时,执行一个语句会碰到以下错误提示: Err ...

  5. SVN Cornerstone 报错信息 xcodeproj cannot be opened because the project file cannot be parsed.

    svn点击update 之后,打开xcode工程文件,会出现  xxx..xcodeproj  cannot be opened becausethe project file cannot be p ...

  6. jquery 面板拖拽

    在网上找了好多的例子 都不满足我所需要 在网上找了一篇关于easyui是一个拓展的demo  然后根据demo 把我所需要的东西进行再次拓展 满足我的需求 也不多说了 上代码 首先 你肯定是要导eas ...

  7. Valgrind 发现程序的内存问题

    参考 : [1]. 应用 Valgrind 发现 Linux 程序的内存问题. http://www.ibm.com/developerworks/cn/linux/l-cn-valgrind/ [2 ...

  8. 我刚知道的WAP app中meta的属性

    之前我一直做的都是WEB前端开发,来北京以后面试了一个移动前端开发,WAP前端开发. 其实在原来公司的时候也做过这方面的开发,可面试的时候面试官问我,要想强制让文档与设备的宽度保持1:1,mate标签 ...

  9. C# 利用反射给不同类型对象同名属性赋值

    public class ObjectReflection { public static PropertyInfo[] GetPropertyInfos(Type type) { return ty ...

  10. 外网无法访问本地IIS站点

    自己申请了个花生壳动态域名,本来是打算在IIs上建个站点测试一下的,路由器上的端口也配置好了,把80端口指向我本机.域名也通过 ping 测试确实指向了我这里的路由器.但是用这个域名老是访问不了我这个 ...