android 中ImageButton按下改变背景图片的效果
|
ImageButton btn = (ImageButton)findViewById(R.id.imageButton1); btn.setOnTouchListener(new View.OnTouchListener(){ public boolean onTouch(View v, MotionEvent event) { if(event.getAction() == MotionEvent.ACTION_DOWN){ //重新设置按下时的背景图片 ((ImageButton)v).setImageDrawable(getResources().getDrawable(R.drawable.android_btn_pressed)); }else if(event.getAction() == MotionEvent.ACTION_UP){ //再修改为抬起时的正常图片 ((ImageButton)v).setImageDrawable(getResources().getDrawable(R.drawable.android_btn)); } return false; } }); |
|
<?xml version="1.0" encoding="utf-8"?> <selectorxmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="false"android:drawable="@drawable/android_btn" /> <item android:state_focused="true"android:drawable="@drawable/android_btn" /> <item android:state_pressed="true"android:drawable="@drawable/android_btn_pressed" /> </selector> |
|
<ImageButton android:id="@+id/imageButton2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@layout/image_btn_press" /> |
android 中ImageButton按下改变背景图片的效果的更多相关文章
- 利用selector设置ImageButton不同状态下的背景图片
1.自定义MyButton类 public class MyButton extends Button { //This constructormust be public MyButton(Cont ...
- 一款基于jquery的下拉点击改变背景图片
今天给大家介绍一款基于jquery的下拉点击改变背景图片.单击右上角的图片,下拉显示可选择的背景图片,单击图片变为背景图.效果图下: 在线预览 源码下载 实现的代码. html代码: <a ...
- React-Native 之 GD (二十)removeClippedSubviews / modal放置的顺序 / Android 加载git图\动图 / 去除 Android 中输入框的下划线 / navigationBar
1.removeClippedSubviews 用于提升大列表的滚动性能.需要给行容器添加样式overflow:’hidden’.(Android已默认添加此样式)此属性默认开启 这个属性是因为在早期 ...
- document.execCommand("BackgroundImageCache",false,true)解决ie6下的背景图片缓存问题
E6下的背景图片每次使用都会重新发送请求(not 本地),连一个hover效果时候同样的背景图片仅仅位置不同而已,ie6都会再次发送请求,这个令人崩溃的事情需要解决掉:对于ie来说,filter:ex ...
- CSS之background-image:在一个元素中设置给定数量的背景图片
众所周知,可以通过设置background-repeat的值来改变背景图片的重复次数.但有一个问题,background-repeat的值不是让图片只有1个,就是让图片铺满.如果只想设置给定数量的图片 ...
- css3-11 如何改变背景图片的大小和位置
css3-11 如何改变背景图片的大小和位置 一.总结 一句话总结:css3相对css2本身就支持改变背景图片的大小和位置. 1.怎么设置背景不填充padding部分? background-orig ...
- 搭建Android+QT+OpenCV环境,实现“单色图片着色”效果
OpenCV是我们大家非常熟悉的图像处理开源类库:在其新版本将原本在Contrib分库中的DNN模块融合到了主库中,并且更新了相应文档.这样我们就能够非常方便地利用OpenCV实 ...
- 基于html5页面滚动背景图片动画效果
基于html5页面滚动背景图片动画效果是一款带索引按钮的页面滚动动画特效代码.效果图如下: 在线预览 源码下载 实现的代码. html代码: <div id="fullpage&q ...
- Android中Selector的用法(改变ListView和Button的默认背景)
Android中的Selector的用法 http://blog.csdn.net/shakespeare001/article/details/7788400#comments Android中的S ...
随机推荐
- Talking Ben App砸壳记
需求: 导出Talking Ben app的头文件 实施: 1)准备材料: 越狱IOS设备一部,并安装Talking Ben游戏 IOS设备上安装open SSH IOS设备的/usr/bin 中安装 ...
- UESTC 1272 Final Pan's prime numbers(乱搞)
题目链接 Description Final Pan likes prime numbers very much. One day, he want to find the super prime n ...
- DigitalOcean VPS简介
DigitalOcean是一家位于美国的云主机服务商,总部位于美国纽约,成立于2012年.由于价格低廉,高性能配置.灵活布置的优势,近些年来发展迅猛,成为中国站长圈们喜爱的品牌.(访问http://w ...
- Arch声卡配置
ALSA Utilities Install the alsa-utils package. This contains (among other utilities) the alsamixer a ...
- ArrayList和LinkedList和Vector源码分析
ArrayList源码: private static final int DEFAULT_CAPACITY = 10;//默认长度 /** * Shared empty array instance ...
- java的克隆
java有深拷贝和浅拷贝的区别. 浅拷贝:他是指拷贝该对象时,仅仅是拷贝了对象的本身(包括对象的基本数据类变量),不会拷贝引用数据类型的变量,也就是拷贝出来的新对象基本数据类型的值不变,引用数据类型的 ...
- ural 1203. Scientific Conference(动态规划)
1203. Scientific Conference Time limit: 1.0 second Memory limit: 64 MB Functioning of a scientific c ...
- mysql建表设置两个默认CURRENT_TIMESTAMP的技巧
转载:http://blog.163.com/user_zhaopeng/blog/static/166022708201252323942430/ 业务场景: 例如用户表,我们需要建一个字段是创 ...
- shell小脚本工具合集
1.将指定内容写入文件 echo "hello world" > file.txt echo "hello world" >> file.tx ...
- Python基础篇-day2
主要内容: for循环 while循环 格式化输出(2) 数据统计及记录 ############################################################# 1 ...