Ich versuche, die Lösungen in diesem Thread zu verwenden:Ändern Hintergrund-Bild der Schaltfläche, wenn darauf geklickt/fokussiert nicht funktioniert
How to change background image of button when clicked/focused
Aber aus irgendeinem Grund nichts funktioniert. Wenn Sie auf die Schaltfläche klicken, ändert sich nichts.
Dies ist die Taste 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"/>
Und das ist die 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>
Und das ist die onClick der Taste():
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
startActivityForResult(intent, ActivityRequestCodes.SELECT_CONTACT);
Was mache ich falsch?