Hello everyone, I'd like to share a case study on how to block click events for Android view components positioned behind an overlay view. To give you an idea of the situation, you can look at the image below.
In the image, you’ll notice an overlay view that causes the background view to appear dimmed. In my case, this is a CardView that I use to signal that the components behind it are disabled, with a transparent color that creates the dimming effect.
The problem is that the click events I assign to the overlay view are passing through to the views behind it, triggering functions linked to those components.
So, is there a way to make the overlay view block click events so they don’t pass through to the views behind it?
Solution
The best way to address this is by setting the overlay view (blocking view) to intercept click events by adding:
android:clickable="true"