Android开发中使用的颜色
来源:互联网 发布:淘宝开店怎么采购商品 编辑:程序博客网 时间:2024/04/28 14:34
Android 开发中使用的颜色可以分为两种,自定义颜色和系统颜色
1.自定义颜色:
颜色值的定义是通过RGB三原色和一个alpha值来定义的(加色原理)。以井号(#)开始,后面是Alpha-Red-Green-Blue的格式。
形如:
#RGB
#ARGB
#RRGGBB
#AARRGGBB
通常使用#RRGGBB 或者#AARRGGBB的形式
1.1 在资源文件中定义颜色:
一般在res\values下建立colors.xml文件,定义颜色,如下:
- <?xml version="1.0" encoding="utf-8"?>
- <resourses>
- <color name="red">#ff0000</color>
- </resourses>
1.2.1 在代码中使用颜色
R.color.color_name
例如:
- Button btn1 = (Button) findViewById(R.id.button1);
- int color = Resources.getSystem().getColor(R.color.red);
- btn1.setBackgroundColor(color);
1.2.2 在布局文件中使用颜色
@[package:]color/color_name
例如:
- <Button
- Android:id="@+id/button1"
- Android:layout_height="wrap_content"
- Android:layout_width="match_parent"
- Android:text="Address book"
- Android:background="@color/red"
- ></Button>
- <pre name="code" class="java"><blockquote style="margin:0 0 0 40px; border:none; padding:0px"><pre name="code" class="java" style="margin-top: 4px; margin-right: 0px; margin-bottom: 4px; margin-left: 0px; background-color: rgb(240, 240, 240); "><Button
- Android:id="@+id/button1"
- Android:layout_height="wrap_content"
- Android:layout_width="match_parent"
- Android:text="Address book"
- Android:background="#ff0000"
- ></Button>
2.系统颜色
Android也有一些内置的颜色,例如系统资源中定义的颜色,十分有限。
Android.graphics.Color类中也提供了一些颜色常量和构造颜色值的静态方法。
2.1 系统颜色的使用
2.1.1 在代码中使用系统颜色
系统资源中定义的颜色值十分有限
Button btn1 = (Button) findViewById(R.id.button1);
- int color = Resources.getSystem().getColor(Android.R.color.background_dark);
- btn1.setBackgroundColor(color);
- Button btn1 = (Button) findViewById(R.id.button1);
- btn1.setBackgroundColor(Color.CYAN);
- Button btn1 = (Button) findViewById(R.id.button1);
- btn1.setBackgroundColor(Color.argb(0xff, 0xff, 0x00, 0x00));
- <Button
- Android:id="@+id/button1"
- Android:layout_height="wrap_content"
- Android:layout_width="match_parent"
- Android:text="Address book"
- Android:background="@android:color/background_dark"
- ></Button>
- Android开发中颜色的使用
- Android开发中使用的颜色
- Android 开发中使用的颜色可以分为两种,自定义颜色和系统颜色
- Android中颜色的使用
- Android中颜色的使用
- Android开发中颜色的定义方法
- android开发中颜色的定义方法
- Android开发中颜色的定义方法
- Android开发中颜色的定义方法
- Android开发中颜色的定义方法
- Android开发中颜色的自定义方法
- Android开发中颜色的自定义方法
- Android开发中常见的颜色
- android 开发中惯用颜色,以及一些颜色的代码
- Android中关于颜色的使用
- Android中十六进制颜色的基本使用
- Android 开发中颜色资源使用详细介绍
- Android调色板的开发与RGB颜色的使用
- 程序员职业情商训练
- Android 获取手机总内存和可用内存等信息
- Java内存分配原理精讲
- WCF Learning(4):WCF中的序列化[上篇]
- AT&T和GAS汇编区别
- Android开发中使用的颜色
- VS2010安装Visual AssistX出现的奇怪事情
- Oracle rowid urowid
- JavaScript跨域总结与解决办法
- 如何编写Linux Daemon后台程序(守护进程)
- 84I9程序
- 一个简单的XML Schema的例子
- javascript整理
- 语不惊人死不休(63)专注摘录