Android: Disable text selection in a webview

后端 未结 7 714
误落风尘
误落风尘 2020-11-27 11:42

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.addJavas

7条回答
  •  我在风中等你
    2020-11-27 12:24

    It appears that cut/paste via long press is turned off if you used

        articleView.setWebChromeClient(new WebChromeClient(){...})
    

    See https://bugzilla.wikimedia.org/show_bug.cgi?id=31484

    So if you are using setChromeClient and you WANT to have long click to start copy/paste, the do the following:

        webView.setWebChromeClient(new WebChromeClient(){
    
            [.... other overrides....]
    
            // @Override
            // https://bugzilla.wikimedia.org/show_bug.cgi?id=31484
            // If you DO NOT want to start selection by long click,
            // the remove this function
            // (All this is undocumented stuff...)
            public void onSelectionStart(WebView view) {
                // By default we cancel the selection again, thus disabling
                // text selection unless the chrome client supports it.
                // view.notifySelectDialogDismissed();
            }
    
        });
    

提交回复
热议问题