如何禁用Android EditText中的粘贴选项 [英] how to disable paste option in android EditText
本文介绍了如何禁用Android EditText中的粘贴选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个要求,其中EditText
不允许粘贴,但应该允许复制.
我尝试了setCustomSelectionActionModeCallback
,但是它禁用了复制选项.
I have an requirement where EditText
doesn't allow paste but it should allow copy.
I tried setCustomSelectionActionModeCallback
but it disable copy option.
EditText etxt = (EditText) findViewById(R.id.editText1);
etxt.setCustomSelectionActionModeCallback(new Callback() {
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
public void onDestroyActionMode(ActionMode mode) {
}
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
return false;
}
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
return false;
}
});
推荐答案
I done my self..credit goes to Android intercept paste\copy\cut on editText
我只是根据自己的需要更改了onTextContextMenuItem().
I just changed onTextContextMenuItem() based on my requirement..
@Override
public boolean onTextContextMenuItem(int id) {
// Do your thing:
//boolean consumed = super.onTextContextMenuItem(id); // Change1
// React:
switch (id){
case android.R.id.cut:
onTextCut();
break;
case android.R.id.paste:
onTextPaste();
return false; //Change2
//break;
case android.R.id.copy:
onTextCopy();
}
return true; // Change3
}
这篇关于如何禁用Android EditText中的粘贴选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文