public class ForbidPasteEditText extends EditText {
public ForbidPasteEditText(Context context) {
super(context);
}
public ForbidPasteEditText(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ForbidPasteEditText(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
requestFocus();
setSelection(getText().toString().length());
}
return true;
}
// @Override
// public boolean onTextContextMenuItem(int id) {
// if (id == android.R.id.paste || id == android.R.id.copy || id == android.R.id.cut) {
Toast.makeText(getContext(), "禁止粘贴", Toast.LENGTH_SHORT).show();
// return true;
// }
// return super.onTextContextMenuItem(id);
// }
}
EditText禁止复制粘贴
最新推荐文章于 2021-12-11 16:54:49 发布