Android: How to TOTALLY disable copy and paste function in Edittext

后端 未结 4 1173
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-11 19:38

I am quite new to Android developing area and recently I hv encountered a tough problem.

I was trying to make a Edittext which should NOT ALLOW user to copy content

4条回答
  •  无人及你
    2020-12-11 20:01

    There is one possibility, by disabling the cursor handler. You won't get the paste button, but you will also not be able to move the cursor with touch.

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getActionMasked() == MotionEvent.ACTION_UP && mDisableCursorHandle) {
            // Hack to prevent keyboard and insertion handle from showing.
            cancelLongPress();
        }
        return super.onTouchEvent(event);
    }
    

提交回复
热议问题