1. 对应的实体类 : ColorStateList
!!! 不做解释 !!!
2. XML 方式
2.1 xml 存放路径 : res/color/filename.xml
2.2 引用方式:
(1) In Java : R.color.filename
(2) In XML : @[package:]color/filename
2.3 XML 语法
android:color="hex_color"
android:state_pressed=["true" | "false"]
android:state_focused=["true" | "false"]
android:state_selected=["true" | "false"]
android:state_checkable=["true" | "false"]
android:state_checked=["true" | "false"]
android:state_enabled=["true" | "false"]
android:state_window_focused=["true" | "false"] />
节点 :
根节点必须是 :
命名空间(xmlns:android)必须是 :http://schemas.android.com/apk/res/android
android:color : 颜色 , 必须指定.
2.4 XML 示例代码
定义
android:color="#ffff0000"/>
android:color="#ff0000ff"/>
使用
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/button_text"
android:textColor="@color/button_text" />