How to have selectableItemBackground on Imageview?
Alternatively you can try this:-
Simply, Wrap your ImageView with CardView
<android.support.v7.widget.CardView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="200dp"
android:clickable="true"
android:focusable="true"
app:cardCornerRadius="4dp"
android:foreground="?android:attr/selectableItemBackground">
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v7.widget.CardView>
Inserting a View
to other ViewGroup
is affecting app performance, so you can just change your ImageView
to ImageButton
and give it ?attr/selectableItemBackground
as background
<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/myButton"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="?attr/selectableItemBackground"
android:scaleType="centerCrop"
app:srcCompat="@drawable/ic_arrow_white" />