Get ripple effect in RecyclerView with elements containing a different background color.

I need a simple ripple effect in RecyclerView elements that have a background color. Since they already have a background color (blue), I cannot set the background to 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 file 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 does not work. :( EDIT: Apparently, the ripple color is hidden behind the background color, so it is almost invisible. But you can see a shade of it in the background (if I set color_view_pressed to dark red). Is there way to achieve this, even otherwise? I tried all possible solutions there. Somehow, it worked fine with ListView. I don’t understand how to do this.

+4
2

ViewGroup , , ( ):

android:foreground="?android:attr/selectableItemBackground"

:

android:clickable="true"
android:focusable="true"

+4

2 ViewGroup, - , - .

+1

Source: https://habr.com/ru/post/1628331/


All Articles