Ripple effect does not work in RelativeLayout

Varun Kumar picture Varun Kumar · Aug 11, 2015 · Viewed 12.2k times · Source

I'm trying to implement ripple effect in a RelativeLayout on API 22 but it doesn't show up. However the same ripple works in a Button.

The code for my ripple drawable is as follows:

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="#d1c4e9">
    <item android:id="@android:id/mask"
        android:drawable="@android:color/white" />
    <item android:drawable="@drawable/rect"/>
</ripple>

Code for Relative Layout is as follows:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:background="@drawable/ripple">
</RelativeLayout>

After this the ripple is set as a background on Button and RelativeLayout. The ripple on button works great but it doesn't show up on the RelativeLayout at all.

Can anyone tell me what am I doing wrong?

Answer

Raghunandan picture Raghunandan · Aug 11, 2015

Adding this attribute android:clickable="true" works. Tested on Nexus 5