删除ImageButton的图像资源

cor*_*ase 7 android imagebutton drawable

我有一个透明的ImageButton.单击时,按钮的ImageResource设置为drawable-hdpi文件夹中的drawable(基本上图像显示在透明ImageButton的顶部).我正在使用这种ImageButton.setImageResource()方法来做到这一点.我的问题是,如何删除图像资源,以便再次只有透明图像按钮.当然,我需要能够在java中执行此操作,而不是XML.我尝试了以下ImageButton.setImageResource(null); 无效的方法:我也看了一下,找不到答案......提前感谢您的帮助.

编辑:谢谢大家的回答.PéterVarga的回答正是我所需要的,所以这就是我的目标.

ᆼᆺᆼ*_*ᆼᆺᆼ 32

尝试设置imageButton.setImageResource(android.R.color.transparent).


The*_*ind 15

imageButton.setBackgroundResource(0);
Run Code Online (Sandbox Code Playgroud)

文件说:

资源应引用Drawable对象或0以删除背景