<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android">    <item android:state_pressed="true" android:state_enabled="true" android:state_window_focused="false"          android:drawable="@drawable/button_pressed" /> <!-- pressed,enable等多个属性 -->    <item android:state_focused="true"          android:drawable="@drawable/button_focused" /> <!-- focused -->    <item android:state_hovered="true"          android:drawable="@drawable/button_focused" /> <!-- hovered -->    <item android:drawable="@drawable/button_normal" /> <!-- default --></selector>

android:drawable放一个drawable资源
android:state_pressed 是否按下,如一个按钮触摸或者点击。
android:state_focused 是否取得焦点,比如用户选择了一个文本框。
android:state_hovered 光标是否悬停,通常与focused state相同,它是4.0的新特性
android:state_selected 被选中,它与focus state并不完全一样,如一个list view 被选中的时候,它里面的各个子组件可能通过方向键,被选中了。
android:state_checkable 组件是否能被check。如:RadioButton是可以被check的。
android:state_checked 被checked了,如:一个RadioButton可以被check了。
android:state_enabled 能够接受触摸或者点击事件
android:state_activated 被激活
android:state_window_focused 应用程序是否在前台,当有通知栏被拉下来或者一个对话框弹出的时候应用程序就不在前台了

注意:如果有多个item,那么程序将自动从上到下进行匹配,最先匹配的将得到应用。(不是通过最佳匹配)
如果一个item没有任何的状态说明,那么它将可以被任何一个状态匹配。

http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList

更多相关文章

  1. Android(安卓)activity的生命周期
  2. Android(安卓)ListView设置Item选中状态
  3. Android(安卓)activity的生命周期
  4. Android(安卓)Q中外部存储盘路径正则表达式的理解
  5. Android(安卓)activity的生命周期
  6. onRetainNonConfigurationInstance和getLastNonConfigurationIns
  7. Android(安卓)NDK Eclipse 集成
  8. Android搜索建议(搜索联想)
  9. android 输入框自动匹配-AutoCompleteTextView

随机推荐

  1. Android(安卓)NavigationView使用详解
  2. Android(安卓)Studio AAPT2 error: check
  3. 基于Android的Word在线预览
  4. Android(安卓)ScrollView 滚动监听
  5. Fragment使用
  6. IntelliJ IDEA/Android(安卓)Studio 翻译
  7. android 防IOS开关SwitchButton
  8. 还有比这更全的Android代码与驱动吗?
  9. Android(安卓)OpenGL ES 播放 yuv420p文
  10. Android(安卓)自定义适配器