资料
状态列表
此 XML 文件为不同状态引用不同位图图形(例如,按下按钮时使用不同的图像)。创建 StateListDrawable。1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:constantSize=["true" | "false"]
android:dither=["true" | "false"]
android:variablePadding=["true" | "false"] >
<item
android:drawable="@[package:]drawable/drawable_resource"
android:state_pressed=["true" | "false"]
android:state_focused=["true" | "false"]
android:state_hovered=["true" | "false"]
android:state_selected=["true" | "false"]
android:state_checkable=["true" | "false"]
android:state_checked=["true" | "false"]
android:state_enabled=["true" | "false"]
android:state_activated=["true" | "false"]
android:state_window_focused=["true" | "false"] />
</selector>
1 | <?xml version="1.0" encoding="utf-8"?> |
1 | <Button |
change-background-image-of-button-when-clicked-focused1
2
3
4
5<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:drawable="@drawable/your_imagename_while_focused"/>
<item android:state_pressed="true" android:drawable="@drawable/your_imagename_while_pressed" />
<item android:drawable="@drawable/image_name_while_notpressed" /> //means normal
</selector>
警告
1 | <?xml version="1.0" encoding="utf-8"?> |
This item is unreachable because a previous item (item #1) is a more general match than this one (Earlier item which masks item)