设置背景变化
addSensor.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub if(event.getAction() == MotionEvent.ACTION_DOWN){ //更改为按下时的背景图片 v.setBackgroundResource(R.drawable.button_style_5); }else if(event.getAction() == MotionEvent.ACTION_UP){ //改为抬起时的图片 v.setBackgroundResource(R.drawable.button_style_4); } return false; } });
设置图片变化
reFresh.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub if(event.getAction() == MotionEvent.ACTION_DOWN){ //更改为按下时的背景图片 //v.setBackgroundResource(R.drawable.qqmail_compose_attach_reupload_pressed); reFresh.setImageResource(R.drawable.camera_take_flip_pressed); }else if(event.getAction() == MotionEvent.ACTION_UP){ //改为抬起时的图片 //v.setBackgroundResource(R.drawable.qqmail_compose_attach_reupload_normal); reFresh.setImageResource(R.drawable.camera_take_flip_normal); } return false; } });
或者使用drable样式
<ImageButton android:id="@+id/back" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_centerVertical="true" android:layout_marginLeft="5dip" android:src="@drawable/back" android:background="@android:color/transparent" />
back.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/back_pre" /> <item android:drawable="@drawable/back_nor" /> </selector>
from : http://yueguc.iteye.com/blog/939686
相关推荐
在android中有一个ImageButton的View,跟Button按钮的区别是可以在Imagebutton上加载一个图片。 从ImageButton这个字面意思上来看,它是一个图片按钮,那么我们就可以使用它做一个我们想要的图片按钮了,但是我们在...
Android 单击选中的ImageButton[]图像数组用法示例,类似于Radio的功能,不过用图片表现,这样可使Android UI更加友好,视觉更漂亮一些,用户轻触图片,即可选中该数据项,比Radio用户体验更好,如截图所示的选中...
android 具有背景图片的按钮 ImageButton的焦点事件以及事件处理
主要介绍了 Android 点击ImageButton时有“按下”的效果的实现的相关资料,需要的朋友可以参考下
主要介绍了Android ImageButton自定义按钮的按下效果的代码实现方法,需要的朋友可以参考下
android写的自定义控件的demo,比较简单基础的例子学习自定义控件。
Android下实现win8的张力回弹效果的imagebutton
Android教您如何使用系统图标定义ImageButton,对于网上流传的关于imagebutton的使用过程大多雷同且不细致,时常出错,本代码已经验证运行,效果还不错!
4.2.14 带图标的按钮(ImageButton) 4.2.15 拖动效果(Gallery) 4.2.16 切换图片(hmgeSwilcher) 4.2.17 网格视图(GridView) 4.2.18 卷轴视图(ScrollView) 4.2.19 进度条(ProgressBar) 4.2.20 拖动条(SeekBar) 4.2.21 ...
最重要的是还全面介绍了如何利用原生的C,C++(NDK)和Python、Lua等脚本语言(AndroidScriptingEnvironment)来开发Android应用,《Android应用开发揭秘》实战性强,书中的每个知识点都有配精心设计的示例,尤为...
《Android应用开发揭秘》全部实例源代码,配合《Android应用开发揭秘》使用 前言 第一部分 准备篇 第1章 Android开发简介 1.1 Android基本概念 1.1.1 Android简介 1.1.2 Android的系统构架 1.1.3 ...
4.11 置换imagebutton按钮 4.12 实现autocompletetextview输入提示 4.13 实现analogclock时钟 4.14 时间选择 4.15 progressbar和handler进度条 4.16 动态排版处理 4.17 listactivity布局- 4.17.1 listactivity介绍 ...
书名:《Android编程入门很简单》(清华大学出版社.王勇)。 压缩打包成2部分,这是第1部分。 本书是一本与众不同的Android学习读物,是一本化繁为简,把抽象问题具体化,把复杂问题简单化的书。本书避免出现...
4.2.14 带图标的按钮(ImageButton) 4.2.15 拖动效果(Gallery) 4.2.16 切换图片(hmgeSwilcher) 4.2.17 网格视图(GridView) 4.2.18 卷轴视图(ScrollView) 4.2.19 进度条(ProgressBar) 4.2.20 拖动条...
Image zoomer provides easy way to add zoom animations to you ImageButton. You can set the animation duration and reverse mode to reverse the animation. Featured in Screenshots Zoom Zoom Reverse ...
android:contentDescription 设置View的备注说明,作为一种辅助功能提供,为一些没有文字描述的View提供说明,如ImageButton。这里在界面上不会有效果,自己在程序中控制,可临时放一点字符串数据。 android:...
Shape Ripple is a library that emulates a ripple like animations with cool tweaks on the go. It runs on API level 11 and upwards. As addition you can even create your own shape renderer through the ...