Reputation: 33
i'm new here and i'm trying to make an ImageButton switch state.
Here's my ImageButton fully functional :
<ImageButton
android:id="@+id/imageButtonEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="@android:color/transparent"
android:contentDescription="@string/desc"
android:onClick="sendEmailIntent"
android:src="@drawable/email_96" />
When i want to use another image when the button is pressed i use this btn_custom_email.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@+drawable/email_96.png" android:state_enabled="false"/>
<item android:drawable="@+drawable/email_pressed_96.png" android:state_enabled="true" android:state_pressed="true"/>
<item android:drawable="@+drawable/email_pressed_96.png" android:state_enabled="true" android:state_focused="true"/>
<item android:drawable="@+drawable/email_96.png" android:state_enabled="true"/>
And change android:src="@drawable/email_96" by android:src="@drawable/btn_custom_email" for my ImageButton. But then my button turn blank with no error.
It's been a few hours i've been looking for help. I tried :
Refrencing a selector drawable from a style results blank imagebutton
Android: Specify two different images for togglebutton using XML
and many more but couln't find why i've got a blank button. Thank you for your time. Have a good night.
Upvotes: 3
Views: 378
Reputation: 38098
This is wrong:
android:drawable="@+drawable/email_96.png"
Should be:
android:drawable="@drawable/email_96"
(no + and no .png)
Same for all 4 lines
Upvotes: 1