最近在用WebView實現(xiàn)EditText時,不希望在雙擊或長按時出現(xiàn)上下文工具欄,因為這樣子不可控,在設置不可點擊時依舊能夠剪切粘貼,所以就在網(wǎng)上搜搜搜。
結果是,大多數(shù)都是
webView.setLongClickable(false);
webView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
return true;
}
});
只是解決了長按的問題,沒有關于雙擊的。
所以,還是自己寫吧!
richView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
switch (motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN:
if (isFastClick()){
return true;
}
break;
case MotionEvent.ACTION_UP:
break;
}
return false;
}
});
private static Map<String, Long> records = new HashMap<>();
private static final int MIN_DELAY_TIME = 1000; // 兩次點擊間隔不能少于1000ms
public static boolean isFastClick() {
if (records.size() > MIN_DELAY_TIME) {
records.clear();
}
//本方法被調用的文件名和行號作為標記
StackTraceElement ste = new Throwable().getStackTrace()[1];
String key = ste.getFileName() + ste.getLineNumber();
Long lastClickTime = records.get(key);
long thisClickTime = System.currentTimeMillis();
records.put(key, thisClickTime);
if (lastClickTime == null) {
lastClickTime = 0L;
}
long timeDuration = thisClickTime - lastClickTime;
return 0 < timeDuration && timeDuration < 500;
}
自己動手,豐衣足食,目前試著沒問題,歡迎指教!