How do you disable all touch events in an Android WebView (or scrolling in particular)? I would like the activity to handle all touch events.
Asked
Active
Viewed 3.5k times
2 Answers
74
mWebView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
Disables all touch events on a WebView
because the touch listener is executed before the default touch behavior of the WebView
. By returning true
the event is consumed and isn't propagated to the WebView
.
Using android:clickable="false"
does not disable touch events.

hpique
- 119,096
- 131
- 338
- 476
-
Then, how to restore the events? Imagine I have to temporarily disable them and then re-enable them when I need. – Hosane Sep 12 '12 at 16:13
-
3Actually, setting both `android:clickable` and longClickable should do the trick for a webview – Romuald Brunet Oct 07 '12 at 18:49
-
Hosane, just change OnTouchListener return false, it will do the trick – Snow Fox Apr 05 '19 at 14:36
1
If I got you right you just have to overwrite the onTouchEvent method.

Octavian Helm
- 39,405
- 19
- 98
- 102
-
Most likely that should work. I was wondering if there was a property or something more straightforward than that. – hpique Oct 04 '10 at 09:09
-
Ah I see well then you might want to try to give your WebView this layout parameter android:clickable="false". I'm not sure if it works but theoretically it should as WebView is inherited from View. – Octavian Helm Oct 04 '10 at 09:14
-
@hpique can you post the solution again. The current ones in the post are not working – OAH Aug 22 '18 at 22:45