- 浏览: 67771 次
- 性别:
- 来自: 长沙
文章分类
最新评论
-
sys1121:
sys1121 写道为什么我这样获取,img图片没变呢..调试 ...
Android WebView调用Js设置byte[]给Img src -
sys1121:
为什么我这样获取,img图片没变呢..调试发现已经调用JS方法 ...
Android WebView调用Js设置byte[]给Img src -
luciferdevil:
iwangxiaodong 写道这样会不会更简单(更多WebV ...
Android WebView调用Js设置byte[]给Img src -
iwangxiaodong:
这样会不会更简单(更多WebView技巧):webview.l ...
Android WebView调用Js设置byte[]给Img src
State List
A StateListDrawable is a drawable object defined in XML that uses a several different images to represent the same graphic, depending on the state of the object. For example, a Button widget can exist in one of several different states (pressed, focused, or niether) and, using a state list drawable, you can provide a different background image for each state.
You can describe the state list in an XML file. Each graphic is represented by an <item> element inside a single <selector> element. Each <item> uses various attributes to describe the state in which it should be used as the graphic for the drawable.
During each state change, the state list is traversed top to bottom and the first item that matches the current state is used—the selection is not based on the "best match," but simply the first item that meets the minimum criteria of the state.
file location:
res/drawable/filename.xml
The filename is used as the resource ID.
compiled resource datatype:
Resource pointer to a StateListDrawable.
resource reference:
In Java: R.drawable.filename
In XML: @[package:]drawable/filename
syntax:
<?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_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>
elements:
<selector>
Required. This must be the root element. Contains one or more <item> elements.
attributes:
xmlns:android
String. Required. Defines the XML namespace, which must be "http://schemas.android.com/apk/res/android".
android:constantSize
Boolean. "true" if the drawable's reported internal size remains constant as the state changes (the size is the maximum of all of the states); "false" if the size varies based on the current state. Default is false.
android:dither
Boolean. "true" to enable dithering of the bitmap if the bitmap does not have the same pixel configuration as the screen (for instance, an ARGB 8888 bitmap with an RGB 565 screen); "false" to disable dithering. Default is true.
android:variablePadding
Boolean. "true" if the drawable's padding should change based on the current state that is selected; "false" if the padding should stay the same (based on the maximum padding of all the states). Enabling this feature requires that you deal with performing layout when the state changes, which is often not supported. Default is false.
<item>
Defines a drawable to use during certain states, as described by its attributes. Must be a child of a <selector> element.
attributes:
android:drawable
Drawable resource. Required. Reference to a drawable resource.
android:state_pressed
Boolean. "true" if this item should be used when the object is pressed (such as when a button is touched/clicked); "false" if this item should be used in the default, non-pressed state.
android:state_focused
Boolean. "true" if this item should be used when the object is focused (such as when a button is highlighted using the trackball/d-pad); "false" if this item should be used in the default, non-focused state.
android:state_selected
Boolean. "true" if this item should be used when the object is selected (such as when a tab is opened); "false" if this item should be used when the object is not selected.
android:state_checkable
Boolean. "true" if this item should be used when the object is checkable; "false" if this item should be used when the object is not checkable. (Only useful if the object can transition between a checkable and non-checkable widget.)
android:state_checked
Boolean. "true" if this item should be used when the object is checked; "false" if it should be used when the object is un-checked.
android:state_enabled
Boolean. "true" if this item should be used when the object is enabled (capable of receiving touch/click events); "false" if it should be used when the object is disabled.
android:state_window_focused
Boolean. "true" if this item should be used when the application window has focus (the application is in the foreground), "false" if this item should be used when the application window does not have focus (for example, if the notification shade is pulled down or a dialog appears).
Note: Remember that Android applies the first item in the state list that matches the current state of the object. So, if the first item in the list contains none of the state attributes above, then it is applied every time, which is why your default value should always be last (as demonstrated in the following example).
example:
XML file saved at res/drawable/button.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/button_pressed" /> <!-- pressed -->
<item android:state_focused="true"
android:drawable="@drawable/button_focused" /> <!-- focused -->
<item android:drawable="@drawable/button_normal" /> <!-- default -->
</selector>
This layout XML applies the state list drawable to a Button:
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="@drawable/button" />
A StateListDrawable is a drawable object defined in XML that uses a several different images to represent the same graphic, depending on the state of the object. For example, a Button widget can exist in one of several different states (pressed, focused, or niether) and, using a state list drawable, you can provide a different background image for each state.
You can describe the state list in an XML file. Each graphic is represented by an <item> element inside a single <selector> element. Each <item> uses various attributes to describe the state in which it should be used as the graphic for the drawable.
During each state change, the state list is traversed top to bottom and the first item that matches the current state is used—the selection is not based on the "best match," but simply the first item that meets the minimum criteria of the state.
file location:
res/drawable/filename.xml
The filename is used as the resource ID.
compiled resource datatype:
Resource pointer to a StateListDrawable.
resource reference:
In Java: R.drawable.filename
In XML: @[package:]drawable/filename
syntax:
<?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_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>
elements:
<selector>
Required. This must be the root element. Contains one or more <item> elements.
attributes:
xmlns:android
String. Required. Defines the XML namespace, which must be "http://schemas.android.com/apk/res/android".
android:constantSize
Boolean. "true" if the drawable's reported internal size remains constant as the state changes (the size is the maximum of all of the states); "false" if the size varies based on the current state. Default is false.
android:dither
Boolean. "true" to enable dithering of the bitmap if the bitmap does not have the same pixel configuration as the screen (for instance, an ARGB 8888 bitmap with an RGB 565 screen); "false" to disable dithering. Default is true.
android:variablePadding
Boolean. "true" if the drawable's padding should change based on the current state that is selected; "false" if the padding should stay the same (based on the maximum padding of all the states). Enabling this feature requires that you deal with performing layout when the state changes, which is often not supported. Default is false.
<item>
Defines a drawable to use during certain states, as described by its attributes. Must be a child of a <selector> element.
attributes:
android:drawable
Drawable resource. Required. Reference to a drawable resource.
android:state_pressed
Boolean. "true" if this item should be used when the object is pressed (such as when a button is touched/clicked); "false" if this item should be used in the default, non-pressed state.
android:state_focused
Boolean. "true" if this item should be used when the object is focused (such as when a button is highlighted using the trackball/d-pad); "false" if this item should be used in the default, non-focused state.
android:state_selected
Boolean. "true" if this item should be used when the object is selected (such as when a tab is opened); "false" if this item should be used when the object is not selected.
android:state_checkable
Boolean. "true" if this item should be used when the object is checkable; "false" if this item should be used when the object is not checkable. (Only useful if the object can transition between a checkable and non-checkable widget.)
android:state_checked
Boolean. "true" if this item should be used when the object is checked; "false" if it should be used when the object is un-checked.
android:state_enabled
Boolean. "true" if this item should be used when the object is enabled (capable of receiving touch/click events); "false" if it should be used when the object is disabled.
android:state_window_focused
Boolean. "true" if this item should be used when the application window has focus (the application is in the foreground), "false" if this item should be used when the application window does not have focus (for example, if the notification shade is pulled down or a dialog appears).
Note: Remember that Android applies the first item in the state list that matches the current state of the object. So, if the first item in the list contains none of the state attributes above, then it is applied every time, which is why your default value should always be last (as demonstrated in the following example).
example:
XML file saved at res/drawable/button.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/button_pressed" /> <!-- pressed -->
<item android:state_focused="true"
android:drawable="@drawable/button_focused" /> <!-- focused -->
<item android:drawable="@drawable/button_normal" /> <!-- default -->
</selector>
This layout XML applies the state list drawable to a Button:
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="@drawable/button" />
发表评论
-
Ext.field.DatePicker汉化
2012-12-08 17:55 1933代码片段: // 放到Ext.application的la ... -
公司Augreal项目构架设计
2012-11-17 12:10 1016最近,公司接了一个移动应用方面的项目Augreal,经 ... -
Android WebView调用Js设置byte[]给Img src
2012-09-16 21:18 3460WebView与JS的相互调用就不在这里罗嗦了, 这里只说 ... -
Android Paint类介绍
2012-09-04 17:25 993/** * Paint类介绍 ... -
Android系统搜索对话框(浮动搜索框)的使用
2012-08-05 11:46 1237当您需要在您的应用程序中提供搜索服务时,您第一个想到的是您的搜 ... -
简述Android触摸屏手势识别
2012-07-18 22:59 1092简述Android触摸屏手势识别 很多时候,利用触摸屏的Fl ... -
Android 利用缓存机制实现文件下载
2012-06-21 13:54 1649在下载文件或者在线浏览文件时,或者为了保证文件下载的正确性,需 ... -
Android 下网络抓包方法 使用tcpdump
2012-04-23 16:13 1142抓包需要tcpdump以及Root权限,tcpdump在本文后 ... -
使用ProGuard遇到“conversion to Dalvik format failed with error 1”错误的解决办法
2011-12-28 10:20 924ProGuard 是 Android 代码混淆工具,对于程序员 ... -
Microlog4Android使用
2011-11-07 19:00 21561. Add the following static var ... -
LinearLayout上onFling事件失效问题
2011-10-11 09:56 40601. 写一个类,实现OnGestureListener, O ... -
实时文件夹
2011-10-03 23:06 704实时文件夹 实时文件夹是一种用来显示由某个ContentP ... -
Android Supporting Multiple Screens
2011-05-14 00:03 973Android被设计为能运行在不同尺寸、不同像素的多种设备的系 ... -
Android处理多种屏幕尺寸
2011-05-13 14:17 15101 默认设置 如果应用程序针对android1.5或更低版本 ... -
Android各种屏幕尺寸
2011-05-13 03:12 1462多分辨率支持 在 ... -
Android处适应布局
2011-05-13 00:48 8891、使用高分辨率[high density display ( ... -
Eclipse将so文件打包到APK中
2011-05-09 16:13 3082使用Eclipse build APK文件,只要将so文件放在 ... -
Android NDK 编程环境搭建
2011-04-28 00:17 7551. 下载Android 1.5 NDK, Release 1 ... -
Android GSM驱动模块-response流程
2011-04-26 15:00 1237前文对request的分析, 终止在了at_send_comm ... -
Android GSM驱动模块-request流程
2011-04-26 14:59 9791. 多路复用I/O机制的运 ...
相关推荐
在Android开发中,`StateListDrawable`是一种非常重要的图形对象,它允许我们根据视图的状态显示不同的图片或者颜色。在本篇文章中,我们将深入探讨`StateListDrawable`的属性及其用法,通过实例来理解其工作原理。...
SelectorViewDrawable用于在运行时为诸如Buttons,TextViews,RadioButtons等的视图创建选择器,而不是在drawable文件夹中添加多个xml资源。 有关教程,请访问我的博客
StateListDrawable是Android SDK中的一个关键组件,它在Android UI开发中扮演着重要角色,尤其在处理视图状态时。这个"应用源码之StateListDrawableSample.zip"压缩包文件显然是为了帮助开发者深入理解并实践如何...
StateListDrawable是Android SDK中的一个关键图形资源类型,它允许开发者根据组件的状态(如按下、聚焦、默认等)显示不同的图像。在Android应用开发中,StateListDrawable常用于按钮、背景和其他视图元素,以实现...
StateListDrawable是Android SDK中的一个关键组件,它在Android图形和UI设计中起着至关重要的作用。这个"Android应用源码之StateListDrawableSample.zip"压缩包提供的源码示例,旨在帮助开发者深入理解如何使用...
StateListDrawable是Android SDK中的一个资源类型,它允许我们在不同的状态下显示不同的图像。这个"小程序源码 StateListDrawableSample.zip"很可能包含了一个小程序或应用的源代码示例,专门用于演示如何使用...
1. 创建一个StateListDrawable对象:`StateListDrawable states = new StateListDrawable();` 2. 定义不同状态的Drawable:例如,我们可以为默认状态和按下状态设置不同的图片。 - 对于默认状态(未被点击):`...
StateListDrawable是Android SDK中的一个关键组件,常用于Android应用的UI开发,特别是在处理不同状态下的图形绘制时。这个"Android应用源码之StateListDrawableSample"是一个示例项目,旨在帮助开发者理解如何使用...
StateListDrawable是Android系统中一个重要的图形资源类型,它允许我们根据组件的状态(如按下、聚焦、默认等)来显示不同的图像。这个"StateListDrawableSample"示例代码旨在帮助开发者深入理解如何在应用程序中...
这种效果通常通过自定义`StateListDrawable`实现,允许开发者根据不同的组件状态显示不同的图形。 `StateListDrawable`是Android系统提供的一个Drawable类,它可以绑定到View的状态上,根据View的不同状态(如按下...
在Android开发中,State List Drawable(状态列表绘制对象)是一种非常重要的资源类型,它允许我们根据组件的状态(如被按下、被聚焦、被选中等)来改变其显示的图像。这个实例“Android State List Drawable状态...
* StateListDrawable:根据不同的状态,设置不同的图片效果 * Button 事件处理: + 点击事件 + 长按事件 + 触摸事件 3. EditText 基础知识点 * 主要属性: + android:hint + android:textColorHint + ...
除了使用`StateListDrawable`来自定义背景外,还可以设置其他属性来进一步定制按钮,如`android:textColor`、`android:textSize`等。 #### 总结 `Button`组件在Android开发中扮演着极其重要的角色。通过合理的...
如果需要在代码中动态设置按钮的点击效果,可以使用`setBackgroundResource()`或`setBackgroundDrawable()`方法,传入我们自定义的StateListDrawable资源。 7. **优化性能**: 尽管自定义Drawable可以提供丰富的...
在安卓Android开发中,创建独特的用户交互体验是提升应用程序吸引力的关键...通过自定义View、使用动画和StateListDrawable,开发者可以创建出吸引用户的独特交互体验。实践这些技巧,你的Android应用将更加生动有趣。
如果需要更复杂的高亮效果,比如自定义背景色或者动画,可以使用StateListDrawable。StateListDrawable可以根据View的状态(如是否被选中)显示不同的图像资源。在XML中定义一个StateListDrawable,然后将其设置为...
- 实现StateListDrawable,为不同状态(如pressed、focused)定义不同Drawable,通过`<item>`标签定义状态和对应的Drawable。 - 利用LevelListDrawable,通过level值的变化来切换Drawable,比如进度条的实现。 - ...
and can effectively be used wherever a conventional image would be displayed, whether it be as a background, ImageView source, inside a StateListDrawable or used as composites in a TextView. ...
- StateListDrawable:根据视图状态(如按下、选中等)显示不同Drawable,常用于按钮和列表项的背景。 - LevelListDrawable:根据特定级别显示不同的Drawable,常用于进度条和评分系统。 - TransitionDrawable:用于...
5. StateListDrawable:状态列表Drawable,可以根据控件的状态(如按下、选中、默认)显示不同的图像。这对于按钮、选择器等需要根据状态改变外观的组件非常有用。 6. LevelListDrawable:层级列表Drawable,根据一...