您的位置:首页 > 移动开发 > Android开发

android-Color State List Resource

2015-12-03 14:35 246 查看
> A
ColorStateList
is
an object you can define in XML that you can apply as a color, but will actually change colors, depending on the state of the
View
object
to which it is applied. For example, a
Button
widget
can exist in one of several different states (pressed, focused, or neither) and, using a color state list, you can provide a different color during each state.

> XML file saved at
res/color/button_text.xml
:

<?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"/> <!-- pressed -->
<item android:state_focused="true"
android:color="#ff0000ff"/> <!-- focused -->
<item android:color="#ff000000"/> <!-- default -->
</selector>


This layout XML will apply the color list to a View:
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/button_text"
android:textColor="@color/button_text" />
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: