我們在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"/>
本人菜鳥一個,有什麼不對的地方希望大家指出評論,大神勿噴,希望大家一起學習進步!