Android,将ImageButton Background设置为Null,并设置onClick Highlight Color

Android,将ImageButton Background设置为Null,并设置onClick Highlight Color,android,imagebutton,Android,Imagebutton,是否可以将ImageButton的背景设置为“@null”并仍然选择onClick高光颜色 非常感谢 编辑 我在ImageButton上使用以下xml,以便android背景为空,但我的自定义背景为: <ImageButton android:id="@+id/m1_btn" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@

是否可以将ImageButton的背景设置为“@null”并仍然选择onClick高光颜色

非常感谢

编辑

我在ImageButton上使用以下xml,以便android背景为空,但我的自定义背景为:

<ImageButton
    android:id="@+id/m1_btn"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@null"
    android:src="@drawable/pause"
    tools:ignore="ContentDescription" />
有了这个解释,有没有一种方法仍然可以实现按钮突出显示onClick


非常感谢

是的,在drawable文件夹中有一个新的xml clickedstates.xml,它定义了当您按下图像按钮时发生的情况以及默认背景。并将此xml作为图像按钮的背景,如@drawable/clickedstates…例如:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">  

<item     android:state_enabled="false"     
android:drawable="@drawable/default_bgnd" />

<item     android:state_focused="true"        
android:drawable="@drawable/new_green" />

<item     android:state_pressed="true"        
android:drawable="@drawable/new_green" />

<item     android:state_checked="true"        
android:drawable="@drawable/new_green"/>

<item     android:state_selected="true"        
android:drawable="@drawable/new_green" /> 
</selector> 


这是否意味着每个ImageButton需要5个不同的ImageButton背景?对于应用程序的一个简单方面来说,似乎需要做很多工作:SHave ust尝试过这个,但它只在第一次单击按钮时起作用,再次单击它并恢复正常,我认为这与我的按钮代码不兼容:SY您想要一个解决方案,使图像按钮具有空背景,当单击/按下它时,它应该改变颜色。上面的xml是您的解决方案。您不需要在xml中包含5个项目,而只需要使用一个,如“状态已按下”、“已选择”、“已聚焦”或单击按钮时希望执行的任何操作,默认情况下,您可以使用一个没有定义android:state的项目有一个默认背景,在您的例子中是null。最后,将其添加到主xml中的图像按钮中。android:background=“@drawable/clickedstates”我想我还没有完全解释我的问题,我会编辑它。您仍然可以使用提供的xml实现这一点。假设您在可绘制文件夹中有单独的暂停和播放图像。像pauseglow.png和playglow.png,只要你点击它就会设置图像按钮。在你的onTouchListener中,使用MotionEvent.ACTION\u DOWN:你可以将它更改为pp\u btn1.setBackgroundResource(R.drawable.clickedstate);哦,好的,太好了,我今晚进去后会试试这个。谢谢
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">  

<item     android:state_enabled="false"     
android:drawable="@drawable/default_bgnd" />

<item     android:state_focused="true"        
android:drawable="@drawable/new_green" />

<item     android:state_pressed="true"        
android:drawable="@drawable/new_green" />

<item     android:state_checked="true"        
android:drawable="@drawable/new_green"/>

<item     android:state_selected="true"        
android:drawable="@drawable/new_green" /> 
</selector>