Disable WebView touch events in Android
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.
How to disable touch event?
The way to ignore a touch event on a webview is quite simple, just do :
mWebView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return false; //returns true if you wan't also ignore the js touch events
}
});
The thing is, I'm not sure the triggered event are from the webview or another view, you need to define it so you can set this same OnTouchListener on the appropriate view.
Android disable passing events to underlying webview
You can attach a View.OnTouchListener
on your TextView that returns true
to prevent propagating touches to the underlying WebView.
findViewById(R.id.textview).setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// return TRUE since we want to consume the event
return true;
}
});
Note that this will prevent all touches on your WebView: scrolls and clicks.
How to disable the content touch in WebView without afecting the double tap zoom .
If you only want to prevent navigations (user following links) then you need to use the shouldOverrideUrlLoading API:
webview.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return true;
}
});
Related Topics
Remove Unwanted White Space in Webview Android
How to Create Listview Inside Dialog
Supporting Amazon and Android Market (Google Play) Links Inside Application
How to Make Space Between Linearlayout Children
How to Set Status Bar Background as Gradient Color or a Drawable in Android
Recyclerview Adapter and Glide - Same Image Every 4-5 Rows
Use 32-Bit Jni Libraries on 64-Bit Android
Android Alarmmanager Setexact() Is Not Exact
Android: How to Download a Video File to Sd Card
Camera Preview Stretched on Few Android Devices
How to Implement Ssl Certificate Pinning While Using React Native
Switch Back/Front Camera on Fly
Remove Animation/Shifting Mode from Bottomnavigationview Android
When Using Alertdialog.Builder with Edittext, The Soft Keyboard Doesn't Pop
How to Repeat Notification Daily on Specific Time in Android Through Background Service