zoukankan      html  css  js  c++  java
  • ImageButton动态改变按钮图片

     

    在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));

  • 相关阅读:
    Python-time和datetime模块
    Python-hashlib模块
    Python-利用flask模块创建web接口
    Python-操作Excel
    2
    1
    8
    7
    HDFS元数据管理实战篇
    使用HttpFS网关从防火墙后面访问HDFS
  • 原文地址:https://www.cnblogs.com/xgjblog/p/3884503.html
Copyright © 2011-2022 走看看