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


myselector.xml文件中内容如下

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:andro>
<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: android:layout_width="wrap_content" android:src="@drawable/myselector"

 

activity文件中:

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

 

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

相关文章:

  • 2021-11-06
  • 2022-12-23
  • 2022-12-23
  • 2021-12-07
  • 2022-12-23
  • 2021-05-20
  • 2021-07-24
猜你喜欢
  • 2022-12-23
  • 2022-01-08
  • 2021-07-02
  • 2021-08-20
  • 2021-11-24
  • 2022-12-23
  • 2021-10-08
相关资源
相似解决方案