Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Disable text selection in a webview

I am using a webview to present some formatted stuff in my app. For some interaction (which are specific to certain dom elements) I use javascript and WebView.addJavascriptInterface(). Now, I want to recognize a long touch. Unfortunately, onLongTouch, in Android 2.3 the handles for text selection are displayed.

How can I turn off this text selection without setting the onTouchListener and return true? (Then, the interaction with the "website" doesn't work anymore.

like image 294
janoliver Avatar asked Feb 24 '11 16:02

janoliver


People also ask

How do I turn off text selection on a web page?

You can use the user-select property to disable text selection of an element. In web browsers, if you double-click on some text it will be selected/highlighted. This property can be used to prevent this.

How do I turn off click on WebView?

Open Play Store on your device, search for Android System WebView and click on it. Now you can see the option of Disable, press it, the app is now disabled.

What is alternative of WebView in android?

Alternatives to WebView If you want to send users to a mobile site, build a progressive web app (PWA). If you want to display third-party web content, send an intent to installed web browsers. If you want to avoid leaving your app to open the browser, or if you want to customize the browser's UI, use Custom Tabs.


1 Answers

This worked for me

mWebView.setOnLongClickListener(new OnLongClickListener() {     @Override     public boolean onLongClick(View v) {         return true;     } }); mWebView.setLongClickable(false); 

I have not tested, if you don't want the vibration caused by the long click, you can try this:

mWebView.setHapticFeedbackEnabled(false); 
like image 192
Samuel Avatar answered Sep 18 '22 15:09

Samuel