如何从webview隐藏文本选择句柄:android

时间:2019-05-07 11:41:16

标签: android layout webview textselection

我有一个自定义的Webview,用户可以在其中选择文本,我想在用户单击底部的某个按钮时隐藏“ TEXT SELECTION HANDLES”,我希望选择文本但要隐藏句柄,如您可以在下面看到:enter image description here

2 个答案:

答案 0 :(得分:1)

// call hideTextSelection() from your onCreate()
 function hideTextSelection(){    
 //SOLUTION 1->   vibration caused by the long click not works here
   webView.setHapticFeedbackEnabled(false);   

   //Solution 2: 
   /*webView.setOnLongClickListener(new OnLongClickListener() {
     @Override
     public boolean onLongClick(View v) {
       return true;
     }
   });
   webView.setLongClickable(false);*/
}


// whenever you wants to select the data ie. after onClicking the button 'from the bottom of your UI', make it to select as below
yourBottomButton.setOnClickListener(new OnClickListener() {
 @Override
 public boolean onClick(View v) {
  webView.setHapticFeedbackEnabled(true);
 }

});

答案 1 :(得分:0)

尝试一下

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