I have this ShapeableImageView
for which I want to handle the click event but without the ripple effect that looks bad because the container is as small as the button and there's no room for the effect to expand nicely. So, I want to disable it for a different custom effect.
<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/button_round"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="2dp"
android:adjustViewBounds="true"
android:src="@drawable/dw_image"
android:scaleType="centerCrop"
android:contentDescription="@string/button_round"
android:focusable="false"
android:clickable="false"
android:foreground="?android:attr/selectableItemBackground"
android:background="@null"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:shapeAppearanceOverlay="@style/Theme.MyApp.RoundCorner"
app:strokeWidth="2dp"
app:strokeColor="@color/timber_green" />
I handle the click like this
findViewById<ShapeableImageView>(R.id.button_profile).setOnClickListener { view ->
(view as ShapeableImageView).setStrokeColorResource(R.color.tasman)
}
My problem is that even if I set focusable
and clickable
as false
, seems like setting the click listener will enable the ripple effect. Can I have the click listener without that effect?
What is strange is that setting android:background
to a ripple effect file of my own, it doesn't work, the effect remains the default one.
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/timber_green" android:radius="12dp">
<item
android:id="@android:id/mask"
android:drawable="@android:color/holo_red_dark" />
</ripple>
<!-- in my layout -->
android:background="@drawable/ripple_effect"