Search code examples
javaandroidwebviewandroid-actionbarandroid-webview

android: how to disable action mode when a user long click on a web view?


How can I disable the action mode. In another word, I want to prevent the action mode from appearing when the user long clicks on a web view that contains a text.


Solution

  • I haven't worked a lot with WebViews in general, but I think one of these should work. I haven't tested any of these though.

    1:

    Set the attribute on the WebView in the XML: android:longClickable="false"

    Or 2:

    Set the above attribute in Java instead of XML:

    your_webview.setLongClickable(false);
    

    Or 3: Override your WebView and return true in the setOnLongClickListener method

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