Adding a ripple effect to an Android RecyclerView item

Suragch
2 min readJan 12, 2019

This is a repost of an answer I wrote on Stack Overflow.

By default a RecyclerView item does not give a visual indication when you touch it. It may be simplest to use one of the following options in your RecyclerView row's background:

  • android:background="?android:attr/selectableItemBackground"
  • android:background="?attr/selectableItemBackground"

However if you are experiencing problems with this method or if you want finer control over the colors, then you can do the following.

Custom Ripple Effect

This answer is starting with this simple Android RecyclerView example. It will look like the following image.

Add selector for pre API 21 devices

Before API 21 (Android 5.0 Lollipop), clicking a RecyclerView item just changed its background color (no ripple effect). That is what we are going to do, too. If you still have users with those devices, they are used to that behavior, so we aren't going to worry about them too much. (Of course, if you really want the ripple effect for them, too, you could use a custom library.)

Right click your res/drawable folder and choose New > Drawable resource file. Call it custom_ripple

--

--