3

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 :

and many more but couln't find why i've got a blank button. Thank you for your time. Have a good night.

Community
  • 1
  • 1
Slam033
  • 33
  • 2

1 Answers1

1

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

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • Thank you very much ! My button is back but it's not working so i've got still work to do. Have a nice day. – Slam033 Jan 29 '14 at 00:14
  • This is another question... make sure you set your listener either in xml or in java code. Have a good day too! – Phantômaxx Jan 29 '14 at 09:39