0

I am trying to use the solutions in this thread:

How to change background image of button when clicked/focused

But for some reason nothing works. When the button is clicked nothing changes.

This is the button in activity_main.xml:

<ImageButton
android:id="@+id/selectContactBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="contacts"
android:textSize="18sp"
android:layout_above="@+id/selectMediaBtn"
android:layout_alignRight="@+id/selectMediaBtn"
android:layout_alignEnd="@+id/selectMediaBtn"
android:background="@drawable/select_contact"/>

And this is the select_contact.xml:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/blocked_mc" />
<item android:drawable="@drawable/select_contact" />  //means normal
</selector>

And this is the button's onClick():

Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
startActivityForResult(intent, ActivityRequestCodes.SELECT_CONTACT);

What am I doing wrong?

Community
  • 1
  • 1
Nom1fan
  • 846
  • 2
  • 11
  • 27

1 Answers1

0

Ok I understood my mistake.

I named the xml under drawables that describes the pressed/unpressed behavior with the same name as the drawable image itself (select_contact.xml).

When I changed it to something else, it worked.

Silly, but it was late and it happens :)

Hope this can help someone.

Nom1fan
  • 846
  • 2
  • 11
  • 27