Android之drawable state各个属性详解
2014-04-23 17:56
274 查看
我们在定义一个drawable的时候可以通过xml定义的drawable对象。它使得一个图片能在不同的状态下显示不同的图案,比如一个Button,它有pressed,focused,或者其它状态,通过使用state list drawable,你就可以为每种状态提供不同的图片。
先看一个范例:
This layout XML applies the state list drawable to a Button:
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没有任何的状态说明,那么它将可以被任何一个状态匹配。
详细的请看官方的API,那里写的更详细~!http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList
先看一个范例:
<?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>
This layout XML applies the state list drawable to a Button:
<Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/button_selector" android:text="点击发送短信" android:onClick="sendmial" android:layout_alignParentBottom="true" />
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没有任何的状态说明,那么它将可以被任何一个状态匹配。
详细的请看官方的API,那里写的更详细~!http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList
相关文章推荐
- Android 手机配office365邮箱
- 转(Android 4.4 Kitkat Phone工作流程浅析(五)__MT(来电)流程分析)
- android USB host APIs中文翻译
- 转(Android 4.4 Kitkat Phone工作流程浅析(四)__RILJ工作流程简析)
- 转(Android 4.4 Kitkat Phone工作流程浅析(三)__MO(去电)流程分析)
- 转(Android 4.4 Kitkat Phone工作流程浅析(一)__概要和学习计划)
- android游戏开发(一)简单的图形渲染
- Android Binder分析四:Java service的注册
- Android常见的按钮监听器实现方式
- Android应用层修改LED指示灯
- Android Permission大全(中文说明)
- 【Android】在有menu键的手机上显示ActionBar上的Menu键
- 用Eclipse编写Android程序的代码提示功能
- Android ContentProvider和Uri详解
- AndroidManifest.xml文件详解(receiver)
- AndroidManifest.xml文件详解(receiver)
- Android:EditText限制文字输入
- android 中apk如何防止反编译?
- Android之EditText
- Android Paint setXfermode