下面来简要的说一下Android开发中如何对某一个Activity进行背景色的设置。下面我以名字为FirstActivity的Activity的背景色的设置进行说明,先说一下Drawable类:

关于Drawable:

A Drawable is a general abstraction for "something that can be drawn." Most often you will deal with Drawable as the type of resource retrieved for drawing things to the screen; the Drawable class provides a generic API for dealing with an underlying visual resource that may take a variety of forms. Unlike a View, a Drawable does not have any facility to receive events or otherwise interact with the user.

Though usually not visible to the application, Drawables may take a variety of forms:

  • Bitmap: the simplest Drawable, a PNG or JPEG image.
  • Nine Patch: an extension to the PNG format allows it to specify information about how to stretch it and place things inside of it.
  • Shape: contains simple drawing commands instead of a raw bitmap, allowing it to resize better in some cases.
  • Layers: a compound drawable, which draws multiple underlying drawables on top of each other.
  • States: a compound drawable that selects one of a set of drawables based on its state.
  • Levels: a compound drawable that selects one of a set of drawables based on its level.
  • Scale: a compound drawable with a single child drawable, whose overall size is modified based on the current level.

更多详情请参考官方网站:

https://developer.android.com/reference/android/graphics/drawable/Drawable.html

-----------------------------------------------------------------------------

对官方的介绍做一个简要的说明(笔者英语不是非常擅长,以下翻译仅供参考):

Drawable就是一个可画的对象,你经常需要按照绘画到屏幕上的资源类型对Drawable进行处理,Drawable类提供一个通用的API,以处理各种格式的可视化资源。Drawable类与View类不同,因为Drawable类没有任何功能用于接收事件或者与用户进行交互。

Drawable类有以下几种类型:

-->Bitmap:最简单的Drawable,资源是PNG或者JPEG图片(官方写到:Android supports bitmap files in a three formats: .png (preferred), .jpg (acceptable), .gif(discouraged).也就是说最好是PNG格式的图片,其次是JPEG格式,最好不要是GIF格式图片)

-->Nine Patch:PNG格式的扩展,可以声明在其内部如何伸缩和放置。

-->Shape:包含简单的绘画命令以修改bitmap中的资源,允许调整资源大小尺寸以更好的适应对应的情况。

-->Layers:一个复合的drawable,在多个图层中,对每一个图层都可以进行绘制。

-->States:一个复合的drawable,基于它自身的情况,选择drawables集中的一个。

-->Levels:一个复合的drawable,基于它自身的级数,选择drawables集中的一个。

-->Scale:一个单一的带有子drawable的drawable,它的总尺寸基于当前等级进行修改。

总之我们根据画图的需求,创建相应的可画对象,就可以将这个可画对象当作一块“画布(Canvas)”,在其上面操作可画对象,并最终将这种可画对象显示在画布上。

-----------------------------------------------------------------------------

好了,进入正题:

1:打开FirstActivity.java的布局文件activity_first.xml,

这一步在xml布局文件中声明。

加入语句:

。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

android:background="@drawable/bgcolor"

。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

2:我们在上一步中声明的变量bgcolor需要进行赋值,赋值在res/value/strings.xml中进行。打开strings.xml,添加语句:

。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

<drawable name="bgcolor">#F0E68C</drawable>

。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

3:基本步骤搞定后,敲入java代码,打开FirstActivity.java,输入一下代码:

。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

//得到Resources类的对象

Resources res = getResources();

//得到Drawable类的对象
        Drawable dra = res.getDrawable(R.drawable.bgcolor);

//设置当前窗口的背景色 
        this.getWindow().setBackgroundDrawable(dra);

。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

Color About——Second的更多相关文章

  1. 【转】c#、wpf 字符串,color,brush之间的转换

    转自:http://www.cnblogs.com/wj-love/archive/2012/09/14/2685281.html 1,将#3C3C3C 赋给background this.selec ...

  2. Python为8bit深度图像应用color map

    图片中存在着色版的概念,二维矩阵的每个元素的值指定了一种颜色,因此可以显示出彩色. 迁移调色板 下述python代码将VOC数据集中的某个语义分割的图片的调色板直接应用在一个二维矩阵代表的图像上 #l ...

  3. (转)System.Drawing.Color的颜色对照表

    经常使用System.Drawing.Color, 本篇介绍一下颜色与名称及RGB值的对应关系. 1. 颜色与名称的对照表(点击下图放大看): 2. 颜色与RGB值对照表: Color.AliceBl ...

  4. 激光打印机的Color/paper, Xerography介绍

    Color Basic 看见色彩三要素: 光源,物体,视觉 加色色彩模型:R,G,B 多用于显示器 减色色彩模型:C,M,Y,K 多用于打印复印 Paper 东亚地区常用A系列标准用纸,在多功能一体机 ...

  5. 安卓工具箱:color of Style

    <?xml version="1.0" encoding="utf-8"?> <resources> <color name=&q ...

  6. UITableView 一直显示滚动条(ScrollBar Indicators)、滚动条Width(宽度)、滚动条Color(颜色)

    在 IOS 中,对 UIScrollView 的滚动条(ScrollBar Indicators)的自定义设置接口,一直都是很少的.除了能自定义简单的样式(UIScrollViewIndicatorS ...

  7. OpenCASCADE Color Scale

    OpenCASCADE Color Scale eryar@163.com Abstract. The color scale is a specialized label object that d ...

  8. Color Transfer between Images code实现

    上计算机视觉课老师布置的作业实现论文:Color Transfer between Images 基本思路是: 1.给定srcImg和targetImg 2.将RGB空间转为Lab空间 3.根据论文中 ...

  9. ZOJ Problem Set - 1067 Color Me Less

    这道题目很简单,考察的就是结构体数组的应用,直接贴代码了 #include <stdio.h> #include <math.h> typedef struct color { ...

  10. UVA - 1625 Color Length[序列DP 代价计算技巧]

    UVA - 1625 Color Length   白书 很明显f[i][j]表示第一个取到i第二个取到j的代价 问题在于代价的计算,并不知道每种颜色的开始和结束   和模拟赛那道环形DP很想,计算这 ...

随机推荐

  1. openvpn - unable to browse internet after connect to openVPN

    Using iptables Use an iptable for NAT forwarding: # iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o ...

  2. 【阿里云产品公测】Opensearch使用体验和评测

    作者:阿里云用户outofmemory 昨天晚上收到了阿里云发的邮件,Open search可以申请公测了,于是迫不及待申请了测试,审核人员很高效,过了不到俩小时给批下来了.  很开心,于是趁今天是周 ...

  3. Windows环境下安装Redis

    1:首先下载redis.从下面地址下:https://github.com/MSOpenTech/redis/releases2:创建redis.conf文件:这是一个配置文件,指定了redis的监听 ...

  4. 【MongoDB】增删改查基本操作

    查看所有数据库 show dbs 切换数据库(若不存在,会自动创建) use databasename 删除当前数据库 db.dropDatabase() MongoDB中没有表,只有集合. 插入集合 ...

  5. HTML <input> 标签的 maxlength 属性

    前端的表单,需要进行验证. 结合JS表单验证框架,写了很多前端验证的代码. 其中,有这么一个需求:用户最多只能输入10个字符. 按照惯性,肯定是会去写JS表单验证了. 实际上,根本没有必要. HTML ...

  6. SQL---------表的约束

    表的约束 防止同一条数据完全重复:主键约束(primary key)唯一键约束(unique),自增长: 防止数据为空: 非空约束(not noll),默认值: 防止乱填数据: 外键, 定义数据类型, ...

  7. MacOS显示和不显示隐藏文件

    defaults write com.apple.finder AppleShowAllFiles Yes && killall Finder //显示隐藏文件 defaults wr ...

  8. Mac下kernel_task占用大量CPU怎么办?

    我们都知道要想让电脑运行的快速,那么就要尽量的保持内存和CPU的充足.不过一些MAC用户发现MAC系统中的Kernel_task会占用大量的CPU,导致电脑发热变卡.这个问题该怎么解决呢? 具体操作步 ...

  9. SQL 复制订阅 异常后 强制删除

    最近做数据库同步备份工作,将 主库 通过SQLService 自带的 [复制] 订阅出去后,因为 订阅方(从库) 发生异常,主库 无法确定 从库的订阅,就想清理了,订阅重新做同步,结果.....主库上 ...

  10. swift创建对象use of undeclared type 自己的类

    在swift项目中,引用自己创建的类,编译会成功的,但是会出现红色感叹号,类似报错,如:swift创建对象use of  undeclared type 自己的类,或者 use of unresolv ...