Disable WebView touch events in Android

hpi*_*que 31 android touch webview

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.

hpi*_*que 66

mWebView.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        return true;
    }
});
Run Code Online (Sandbox Code Playgroud)

禁用a上的所有触摸事件,WebView因为触摸侦听器在默认触摸行为之前执行WebView.通过返回true事件被消耗并且不会传播到WebView.

使用android:clickable="false"不会禁用触摸事件.

  • 实际上,设置`android:clickable`和longClickable应该可以实现webview的技巧 (3认同)