activity_main.xml
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F4F0EC"
android:padding="16dp"
tools:context=".MainActivity">
<!-- ImageButton with default click effect/pressed state -->
<ImageButton
android:id="@+id/ib"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="64dp"
android:src="@drawable/share_transparent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<!--
ImageButton with custom pressed state.
ImageButton selector.
ImageButton click effect.
A transparent png image used for ImageButton.
-->
<ImageButton
android:id="@+id/ib2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="48dp"
android:src="@drawable/share_transparent"
android:background="@drawable/image_button_selector"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/ib" />
</androidx.constraintlayout.widget.ConstraintLayout>
res/drawable/image_button_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<!--image button pressed state background color-->
<item android:state_pressed="true">
<shape android:shape="rectangle">
<solid android:color="#C0BB91" />
<corners android:radius="5dp"/>
</shape>
</item>
<!--image button focused state background color-->
<item android:state_focused="true">
<shape android:shape="rectangle">
<solid android:color="#E4E6D5" />
<corners android:radius="5dp"/>
</shape>
</item>
<!--image button default background color-->
<item>
<shape android:shape="rectangle">
<solid android:color="#E4E6D5" />
<corners android:radius="5dp"/>
</shape>
</item>
</selector>


- How to create an ImageView programmatically in Android
- How to set a bitmap to ImageView in Android
- How to set ImageView image from Assets in Android
- How to programmatically set image to ImageView in Android
- How to set an image to ImageView in XML in Android
- How to set an image to ImageView in Android
- How to create a custom Title for DatePickerDialog in Android
- How to set DatePickerDialog max date and min date in Android
- How to use theme in DatePickerDialog in Android
- How to format DatePickerDialog selected date in Android
- How to get AM PM value from TimePickerDialog in Android
- How to change TimePickerDialog theme in Android
- Android TimePickerDialog Example
- How to add padding to an ImageButton in Android
- How to set an ImageButton background transparent in Android