隐藏安卓webview文本选择的复制粘贴按钮
时间: 2024-01-27 17:40:23 浏览: 155
要隐藏Android Webview中文本选择的复制和粘贴按钮,可以使用以下代码:
```java
webView.setLongClickable(false);
webView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_UP) {
if (!v.hasFocus()) {
v.requestFocus();
}
}
return false;
}
});
webView.setWebChromeClient(new WebChromeClient() {
@Override
public void onProvideCustomView(View view, WebChromeClient.CustomViewCallback callback) {
super.onProvideCustomView(view, callback);
}
@Override
public void onHideCustomView() {
super.onHideCustomView();
}
@Override
public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) {
return true;
}
});
```
这个代码将禁用长按文本选择和上下文菜单,并防止出现复制和粘贴按钮。
阅读全文