android中施用selector动态改变imageView或ImageButton的背景
发布时间:2011-06-27 20:28:43 文章来源:www.iduyao.cn 采编人员:星星草
android中使用selector动态改变imageView或ImageButton的背景
做应用时,可能会需要动态改变控件的背景图片,如果仅仅是简单的点击,选中之类的事件,如果靠程序中写监听的代码就显得太麻烦了,在这种情况下,你可以使用selector动态改变控件背景拉:)
1。在res/drawable目录下建一个mybutton.xml文件,根据需要,不同的状态下建立不同的item,并对应相应的图片
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false"
android:drawable="@color/transparent" />
<!-- Even though these two point to the same resource, have two states so the drawable will invalidate itself when coming out of pressed state. 注意这句话-->
<item android:state_focused="true" android:state_enabled="false"
android:state_pressed="true"
android:drawable="@drawable/selector_background_disabled" />
<item android:state_focused="true" android:state_enabled="false"
android:drawable="@drawable/lselector_background_disabled" />
<item android:state_focused="true" android:state_pressed="true"
android:drawable="@drawable/selector_background_transition" />
<item android:state_focused="false" android:state_pressed="true"
android:drawable="@drawable/selector_background_transition" />
<item android:state_focused="true"
android:drawable="@drawable/selector_background_focus" />
</selector>
2。在构造layout是引用这个xml
<ImageButton
android:id="@+id/ImageButton01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/mybutton">
</ImageButton>
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。
其他相似内容:
-
关于opengl源码的问题
gluPickMatrix函数的实现在哪?我在glut源码中找了半天没有找到
------解决方案--------------------
这是...
-
关于傅立叶变换的数字水印嵌入算法的问题
需求:
首先对图像和水印图像进行傅里叶变换;
讲数字水印嵌入到图像中;
逆变换显示潜入水印...
-
Matlab和OpenCV的处理速度问题
大家好!我正准备用Windows下的OPENCV实现MSR算法来处理图像,目前已经有在Matlab下面的处理的程序,但...
-
问一个Ghostscript的问题!
我用Ghostscript API将eps转换成pdf,在其他的环境下都能很好的执行。但是在windows server 2008上却不行...
-
求教D3D9.DLL为什么没有被游戏进程加载?
我本来想wrap一下D3D9.DLL给一个3D游戏搞点破坏,但用IcdSword监视一下游戏使用模块,发现连D...
-
请教几个DirectX的问题
1:切线贴图就是法线贴图的意思么?
如果不是,那两者有什么区别?
2:The NPatch mode segments 是什么意思?
原文:
...
-
用OpenCV作的一个车牌识别程序
新手用OpenCV作的一个车牌识别程序,目前只能处理黄底黑字
的车牌图像,供大家交流学习之用。如果感...
-
求助:用matlab实现图像的dct变换
如题
用matlab实现图像的dct变换
不要用自带的dct2函数
多谢了
------解决方案----------------...
-
建了一个群,OCR字符识别技术,欢迎大家加入!
欢迎大家讨论各种字符的识别技术,从图像的预处理到最后分类识别的过程都可以讨论。
qq...
-
Matlab下怎么才能把封闭曲线作为边界判断区域内外
大家好!我对一幅图进行边缘分割,得到了边缘(是一条曲线),下一步想要用得到的边缘曲...