Reputation: 1270
I need a simple ripple effect in my RecyclerView elements, which have a background color set. Since they have a background color(blue) set already, I can't set the background to the drawable/ripple.xml:
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/color_view_pressed"> <!-- ripple color -->
<item android:drawable="@android:color/white"/>
<!-- normal color -->
So I changed my ripple.xml to:
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/color_view_pressed"> <!-- ripple color -->
<item android:drawable="@android:color/blue"/>
<!-- normal color -->
It still doesn't work. :( EDIT: Apparently, the ripple color is getting hidden behind the background color, so it is almost not to be seen. But one can see a tinge of it in the background(if I set color_view_pressed to a dark red color). Is there any way I can achieve that even otherwise? I have tried all possible solutions out there. Somehow, it was working perfectly well with the ListView. I don't understand how though.
Upvotes: 4
Views: 785
Reputation: 3775
In the root ViewGroup
of the layout used for items add foreground attribute instead of background (that you have already set):
android:foreground="?android:attr/selectableItemBackground"
and also set these attributes:
android:clickable="true"
android:focusable="true"
This worked for me
Upvotes: 5
Reputation: 540
You can have 2 ViewGroup
s that will have a background - the top one for the ripple, and it's child to have the entire layout with the blue background.
Upvotes: 1