Android – image button with @ null background (transparent) [copy]
See the English answer > how to set image button background image for different state? I have an image button with a transparent image source, but the background color of the image button is a typical gray button color
I want to set the background = @ null, which is good
However, when I press this image button, I can't see the color indicating that I press the button
If I delete background = @ null when I press the button, please change the color that the user knows you press
I read that you can create an XML with three images, specify the time to press the button, this normal situation and when to focus. But I think there is an easier way
resolvent:
According to the above answer, use the selector drawable (for the background, not null) to set the default state to transparent color:
* selector_ with_ transparency:*
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" android:drawable="@drawable/pressed" />
<item android:drawable="@drawable/transparent" />
</selector>
Press:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#0077cc" />
</shape>
Transparency:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#00000000"/>
</shape>
Then for imagebutton:
background = "@drawable/selector_with_transparency"