In xml, I often do this to emulate onClick
effect:
<android.support.v7.widget.CardView
android:id="@+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:foreground="?selectableItemBackground">
...
</android.support.v7.widget.CardView>
Is there any way to access ?selectableItemBackground
in java?
For those who work with Kotlin, here are some extensions functions to add Ripple on Android View type :
Try below code.
For appcompat you can use,
I was looking for the same solution. I slightly changed this answer to make it more suitable for the asked question. Call the following code from your constructor.
You should reference it as
android.R.attr.selectableItemBackground