Home » Android » android – Ripple effect on custom navigation drawer

android – Ripple effect on custom navigation drawer

Posted by: admin June 15, 2020 Leave a comment

Questions:

I’m developing my first app providing to it the new material look. I’m a bit lost with this so I’m following some tutorials to implement things like Toolbar, Navigation Drawer, etc. I have to say that I’m doing it providing compatibility to pre-lollipop android versions, so I’m using support libraries.

What concers to my question, is that I have just implemented the Navigation Drawer following one of this tutorials and using the following libraries for compatibility:

support.v4.widget.DrawerLayout
support.v7.widget.RecyclerView

I think that the code implementation is too long to put it here, so I’ll provide the link to this tutorial, I have done it exactly as is said here.

My problem is that, when I select one item from the navigation drawer’s row, it perfectly opens it correspondant frament, but, it doesn’t show any ripple effect, or simply any touch effect, when touching it. Something like this:

enter image description here

I have taken a look to some other tutorials, for example, to the one to which belongs the attached gif, to see if they use any method or implementation to provide that efect to the touch, but nothing is implemented to get that effect, just the onclick method.

So, what’s wrong with this code, and how could I modify it, or what could I add to get that effect?

How to&Answers:

As you are using appcompat you can add this to the XML for your navigation drawer item android:background="?attr/selectableItemBackground".

This should provide the ripple effect on Lollipop devices and a fallback grey highlight for older devices.