如何禁用复制/粘贴/到的EditText [英] How to disable copy/paste from/to EditText

查看:154
本文介绍了如何禁用复制/粘贴/到的EditText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,有一个注册页面,在这里我不希望用户能够复制/粘贴文本到的EditText 字段。我设置了 onLongClickListener 每个的EditText ,以便显示复制/粘贴/ inputmethod和其他选项的上下文菜单不出现。因此,用户将不能够复制/粘贴到编辑的字段。

In my application, there is a registration screen, where i do not want the user to be able to copy/paste text into the EditText field. I have set an onLongClickListener on each EditText so that the context menu showing copy/paste/inputmethod and other options does not show up. So the user won't be able to copy/ paste into the Edit fields.

 OnLongClickListener mOnLongClickListener = new OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            // prevent context menu from being popped up, so that user
            // cannot copy/paste from/into any EditText fields.
            return true;
        }
    };

但是,如果用户启用第三方键盘比机器人默认其他,可以具有一个按钮复制/粘贴或可显示相同的上下文菜单中的问题出现了。那么,如何禁用复制/粘贴在这种情况?

But the problem arises if the user has enabled a third-party keyboard other than the Android default, which may have a button to copy/paste or which may show the same context menu. So how do i disable copy/paste in that scenario ?

请让我知道,如果有其他的方法可以复制/粘贴为好。 (也可能是如何将其禁用)

Please let me know if there are other ways to copy/paste as well. (and possibly how to disable them)

任何帮助将是AP preciated。

Any help would be appreciated.

推荐答案

如果您使用的是API级别11或以上,那么你可以停止复制,粘贴,出现被切割和自定义上下文菜单。

If you are using API level 11 or above then you can stop copy,paste,cut and custom context menus from appearing by.

edittext.setCustomSelectionActionModeCallback(new ActionMode.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;
            }
        });

返回false从onCreateActionMode(ActionMode,菜单)将prevent被启动的操作模式(全选,剪切,复制和粘贴操作)。

这篇关于如何禁用复制/粘贴/到的EditText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆