android 解决webView页面双击出现复制剪切等

来源:互联网 发布:淘宝打折软件哪个好用 编辑:程序博客网 时间:2024/06/06 11:36

我们在app中使用webView控件的时候,为我们提供了更多的方便,同时也是有很多问题需要我们解决的,就如今天这个问题,web view中有输入框,当我双击输入框的时候,就会出现复制剪切等操作的栏,这个很影响用户体验,因此我们需要把它禁掉。

我们需要自定义webView:

public class MyWebView extends WebView {    private long lastTime = 0L;    public MyWebView(Context context) {        super(context);    }    public MyWebView(Context context, AttributeSet attrs) {        super(context, attrs);    }    @Override    public boolean onTouchEvent(MotionEvent event) {        switch (event.getAction()) {            case MotionEvent.ACTION_DOWN:                long currentTime = System.currentTimeMillis();                long time = currentTime - lastTime;                if (time < 300) {                    lastTime = currentTime;                    return true;                } else {                    lastTime = currentTime;                }                break;        }        return super.onTouchEvent(event);    }

然后使用我们自定义的webView就可以了:

<MyWebView    android:id="@+id/activity_comment_web"    android:layout_width="match_parent"    android:layout_height="match_parent"/>

本人菜鸟一个,有什么不对的地方希望大家指出评论,大神勿喷,希望大家一起学习进步!

原创粉丝点击