android开发 color state list
2011-11-08 15:57
375 查看
一个ColorStateList是一个对象,定义在xml中,用它作为颜色值来使用。但是否显示出颜色取决于视图对象的状态。例如,一个按钮有几个不同的状态(按下,获得焦点)
,可以使用color state list使它在不同的状态显示出不同的颜色。
每种颜色定义在<item>元素中,用它的属性来描述各种状态,<item>放在唯一的根结点<selecor>中。
语法:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
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"] />
</selector>
例子:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:color="#ffff0000"/>
<item android:state_focused="true"
android:color="#ff0000ff"/>
<item android:color="#ff000000"/> </selector>
将布局应用到视图元素中:
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/button_text"
android:textColor="@color/button_text" />
,可以使用color state list使它在不同的状态显示出不同的颜色。
每种颜色定义在<item>元素中,用它的属性来描述各种状态,<item>放在唯一的根结点<selecor>中。
语法:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
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"] />
</selector>
例子:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:color="#ffff0000"/>
<item android:state_focused="true"
android:color="#ff0000ff"/>
<item android:color="#ff000000"/> </selector>
将布局应用到视图元素中:
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/button_text"
android:textColor="@color/button_text" />
相关文章推荐
- Android按钮文字变色(使用 ColorStateList)
- Android开发艺术探索<Drawable系列之四StateListDrawable >
- Android应用资源---状态颜色列表(Color State List)
- [Android]代码实现ColorStateList及StateListDrawable
- Android-Color State List用于控件在各状态下的文本颜色显示
- Android学习 之 ColorStateList按钮文字变色
- Android ColorStateList使用
- [Android]代码实现ColorStateList及StateListDrawable
- [Android]代码实现ColorStateList及StateListDrawable
- Android: Color State List Resource (颜色申明列表资源)
- android-Color State List Resource
- Android 代码设置TextView 字体颜色--ColorStateList
- Android学习 之 ColorStateList按钮文字变色
- Android按钮设置文字变色ColorStateList
- Android应用资源---状态颜色列表(Color State List)
- Android学习 之 ColorStateList按钮文字变色
- android-Failed to inflate ColorStateList, leaving it to the framework错误
- android的文本状态选择器-ColorStateList
- Android学习 之 ColorStateList按钮文字变色
- android ColorstateList着色