代码核心

import android.os.SystemClock;
import android.view.ViewConfiguration;

/**
 * 防快速点击
 */
public class CheckDoubleClick {

    private static long lastClickTime = 0;

    public static boolean isFastDoubleClick() {
        long time = getBoostTimeMillis();
        long timeD = time - lastClickTime;
        if (0 < timeD && timeD < ViewConfiguration.getLongPressTimeout()) {
            return true;
        }
        lastClickTime = time;
        return false;
    }

    private static long lastClickTime2 = 0;

    public static boolean isFastDoubleClick(long l) {
        long time = getBoostTimeMillis();
        long timeD = time - lastClickTime2;
        if (0 < timeD && timeD < l) {
            return true;
        }
        lastClickTime2 = time;
        return false;
    }

    /**
     * 使用开机计时
     * 替代System.currentTimeMillis()
     * 可以防止修改手机时间导致判断时间间隔不对
     * @return
     */
    public static long getBoostTimeMillis() {
        return SystemClock.elapsedRealtime();
    }

}

使用方式

mIvHalfbd.setOnClickListener(view -> {
            //防止频繁点击
            if (CheckDoubleClick.isFastDoubleClick(3000)) {
                ToastUtil.showToast(R.string.don_not_fast_double_click_during_3_second);
                mIvHalfbd.setChecked(false);
            } else {
                changeMode(HALF_BODY_MODE);
            }
        });