EditText禁用复制粘贴
2017-11-14 本文已影响248人
DreamerYZ
/**
* 禁止输入框复制粘贴菜单
*/
public void disableCopyAndPaste(EditText editText) {
try {
if (editText == null) {
return ;
}
//处理长按事件
editText.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
return true;
}
});
//禁用长按
editText.setLongClickable(false);
editText.setTextIsSelectable(false);
//禁用ActonMode弹窗
editText.setCustomSelectionActionModeCallback(new android.view.ActionMode.Callback() {
@Override
public boolean onCreateActionMode(android.view.ActionMode mode, Menu menu) {
return false;
}
@Override
public boolean onPrepareActionMode(android.view.ActionMode mode, Menu menu) {
return false;
}
@Override
public boolean onActionItemClicked(android.view.ActionMode mode, MenuItem item) {
return false;
}
@Override
public void onDestroyActionMode(android.view.ActionMode mode) {
}
});
} catch (Exception e) {
e.printStackTrace();
}
}