Vị trí file:
- res/color/filename.xml –
res/drawable/filename.xml
Lớp sử dụng: ColorStateList
Gọi sử dụng:
In Java: R.color.filename
In XML: @[package:]color/filename
Cú pháp:
<!-- language: lang-xml --> <selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:color="hex_color" android:drawable="@drawable/button_pressed" 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"] /> </selector>
Thành phần:
- android:drawable – Ảnh đổi
- android:color – màu đổi
Sử dụng:
File: res/color/button_text.xml
<!-- language: lang-xml --> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <!-- pressed --> <item android:state_pressed="true" android:color="#ffff0000"/> <!-- focused --> <item android:state_focused="true" android:color="#ff0000ff"/> <item android:color="#ff000000"/> <!-- default --> </selector>
Sử dụng:
<Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/button_text" android:textColor="@color/button_text" />
Nguồn: http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList