在drawable 目录下增加一个myselector.xml文件,appwidget_play.png,appwidget_played.png

myselector.xml文件中内容如下

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false"
        android:drawable="@drawable/appwidget_play" />  <!-- 正常情况下imagebutton效果 -->

<item android:state_focused="false" android:state_pressed="true"
        android:drawable="@drawable/appwidget_played" /> <!-- 按下后imagebutton效果 -->>
</selector>

layout文件中:

<ImageButton android:layout_height="wrap_content" 
android:background="#00000000" android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:src="@drawable/myselector"

activity文件中:

iImageButton = (ImageButton) findViewById(R.id.imageButton1);

这里不需要在设置iImageButton.setImageDrawable(getResources().getDrawable(R.drawable.appwidget_play));

ImageButton动态改变按钮图片的更多相关文章

  1. Android ImageButton单击切换按钮图片效果

    正常状态的效果: 按钮按下的效果图片: 一.在java中为图片按钮增加触摸监听的函数来实现图片切换,代码如下: ImageButton btn = (ImageButton)findViewById( ...

  2. Cocos Creator 动态改变sprite图片

    首先将存放图片最外层文件夹命名为resources changeBj: function(){ var url = 'globalUI/video/gVideoPlayClick'; var _thi ...

  3. Egret动态设置按钮的图片

    参考: 动态设置Button按钮的状态图片 按钮有3个状态,up down disabled.这里区别于source,source.down,source.disabled,而是每个状态单独一个ima ...

  4. 解决javascript动态改变img的src属性图片不显示问题

    首先讲下这个bug的出现的情况,页面中有<a href="JavaScript:void(0)" onclick="document.getElementById( ...

  5. Atitit 动态按钮图片背景颜色与文字组合解决方案

    Atitit 动态按钮图片背景颜色与文字组合解决方案 转换背景颜色,setFont("cywe_img", fontScale, 50, 5) 设置文字大小与坐标 文字分拆,使用字 ...

  6. css 鼠标移动到按钮图片改变;图片换层;鼠标放上透明度改变直到隐藏;

    css 鼠标移动到按钮图片改变: 方法一: <style> .pp a { width:575px; height:157px; background:url(1.jpg);/*图片地址* ...

  7. 通过html5的range属性动态改变图片的大小

    range属性已经是很成熟的属性了,我们可以使用这个属性进行动态调整图片的宽度,其中原理在于通过不断获取range的值,并赋予给所需要的图片,进而达到动态改变图片的效果.下面贴出具体的代码,主要参照了 ...

  8. 使用jQuery动态改变图片显示大小

    当我们要显示后台传过来若干个尺寸不一的图片时,为了保证图片大小的一致性及比例的协调,需要动态改变图片显示尺寸.通过搜索,我们可以从网上找到实现此 功能的jQuery代码如下.这段代码可以使图片的大小保 ...

  9. javascript生成表格增删改查 JavaScript动态改变表格单元格内容 动态生成表格 JS获取表格任意单元格 javascript如何动态删除表格某一行

    jsp页面表格布局Html代码 <body onload="show()"> <center> <input type="text" ...

随机推荐

  1. 用Javascript轻松制作一套简单的抽奖系统

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN"> <html> <head ...

  2. Digital controller compensates analog controller

    Emerging digital ICs for power control lack basic features, such as the built-in gate drive and curr ...

  3. TRF7970A IC Communication Interface

    General Introduction The communication interface to the reader can be configured in two ways: with a ...

  4. OOW 2015 MYSQL

    https://events.rainfocus.com/oow15/catalog/oracle.jsp?search.event=openworldEvent&search.mysql=d ...

  5. C# http Get/POST请求封装类

    C#HttpHelper官方产品发布与源码下载---苏飞版 http://www.sufeinet.com/thread-3-1-1.html 在C#用HttpWebRequest中发送GET/HTT ...

  6. linux 多线程查看工具

    参考: http://www.oschina.net/translate/command-line-tools-to-monitor-linux-performance?cmp&p=1 htt ...

  7. jq设置样式

    单个样式: $(this).css("color","red"); 多个样式: $(this).css({color:"red",backg ...

  8. Introducing ASP.NET Core: The New ASP.NET in Town!

    The new version of ASP.NET is called ASP.NET Core (a.k.a ASP.NET 5) and it has the most significant ...

  9. PhD Positions opening at University of Nevada, Reno (Wireless Networking / Cognitive Radio / Wireless Security)

    PhD Positions opening at University of Nevada, RenoDept. of Computer Science and Engineering Researc ...

  10. 用500行Julia代码开始深度学习之旅 Beginning deep learning with 500 lines of Julia

    Click here for a newer version (Knet7) of this tutorial. The code used in this version (KUnet) has b ...