R.color
public static final class R.color
extends Object
java.lang.Object | |
↳ | android.R.color |
Summary
Constants | |
---|---|
int | background_dark |
int | background_light |
int | black |
int | darker_gray |
int | holo_blue_bright A really bright Holo shade of blue |
int | holo_blue_dark A dark Holo shade of blue |
int | holo_blue_light A light Holo shade of blue |
int | holo_green_dark A dark Holo shade of green |
int | holo_green_light A light Holo shade of green |
int | holo_orange_dark A dark Holo shade of orange |
int | holo_orange_light A light Holo shade of orange |
int | holo_purple A Holo shade of purple |
int | holo_red_dark A dark Holo shade of red |
int | holo_red_light A light Holo shade of red |
int | primary_text_dark |
int | primary_text_dark_nodisable |
int | primary_text_light |
int | primary_text_light_nodisable |
int | secondary_text_dark |
int | secondary_text_dark_nodisable |
int | secondary_text_light |
int | secondary_text_light_nodisable |
int | tab_indicator_text |
int | tertiary_text_dark |
int | tertiary_text_light |
int | transparent |
int | white |
int | widget_edittext_dark
|
Color
用XML格式定义的颜色值。用RGB值和alpha通道指定颜色值。可以在任何接受十六进制颜色值的地方使用color资源。还能在XML里用到drawable资源时使用color 资源(比如:android:drawable="@color/green")。
颜色值总是以(#)字符开头,后面跟着Alpha-红-绿-蓝信息,格式如下之一:
· #RGB
· #ARGB
· #RRGGBB
· #AARRGGBB
注意:color是简单类型资源,是用名称(name)属性(而非XML文件名)来直接引用的。因此,在一个XML文件里,可以把color资源和其他简单类型资源一起放入一个<resources>元素下。
文件位置:
res/values/colors.xml
文件名可随意指定。<color>元素的名称name将被用作资源ID。
资源引用:
Java代码:R.color.color_name
XML代码:@[package:]color/color_name
语法:
<?xml version="1.0" encoding="utf-8"?>
name="color_name"
>hex_color</color>
</resources>
元素:
必填项。必须是根节点。
无属性。
十六进制表示的颜色值。如上所述。
属性:
name
String类型。颜色的名称,用作资源ID。
示例:
存放在res/values/colors.xml的XML文件:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="opaque_red">#f00</color>
<color name="translucent_red">#80ff0000</color>
</resources>
以下应用程序代码取出color资源:
Resources res = getResources();
int color = res.getColor(R.color.opaque_red);
以下布局(layout)XML将color资源用于属性:
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@color/translucent_red"
android:text="Hello"/>