w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Navigation drawer onClick in items ripple effect lost

I've faced the same problem ... the solution is not documented good enough, but here it is.

Create a selector drawable in your drawable-v21 folder:


    <?xml version="1.0" encoding="utf-8"?>
        <item android:drawable="@color/primary_dark"
android:state_activated="true" />
        <item android:drawable="@color/primary"
android:state_checked="true" />
        <item android:state_pressed="true">
            <ripple android:color="@color/primary" />
        <item android:drawable="@color/background_light" />

As you can see in the code above, the magic is done by adding the <ripple ... /> element above. It's available in v21+ only, so that's why you have to declare separate selectors for -v21 and normal.

Lastly, just put this selector drawable as background of the desired element, in your case the ListView item.

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.