【问题标题】:How to disable the,Paste,selectALL for the editText view如何为editText视图禁用,粘贴,全选
【发布时间】:2017-03-14 09:39:55
【问题描述】:

我有一个登录片段。对于密码(Edittext),我需要禁用粘贴并选择所有选项。

我尝试了setCustomSelectionActionModeCallback 和“set longClickable”,但它们不起作用。 任何建议提前谢谢

【问题讨论】:

标签: android android-edittext copy-paste


【解决方案1】:
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;
            }
        });

从 onCreateActionMode(ActionMode, Menu) 返回 false 将阻止启动操作模式(全选、剪切、复制和粘贴操作)。

【讨论】:

  • 它不像我试过的那样工作,全选功能不起作用,但它仍然在双击显示,但我不需要在整个应用程序中显示菜单粘贴和 selectAll 明智的做法.
【解决方案2】:

这肯定行得通
您只需在 onCreateActionMode() 中添加 mode.finish()

mEntryText.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) {

        /* This is done to solve the issue of SELECT ALL PASTE etc., showing up.
         mode.finish() should not be called at this point. If called, it will throw
         this exception "E/DecorView[]: Destroying unexpected ActionMode instance of TYPE_FLOATING;
         com.android.internal.view.FloatingActionMode@2e022bc was not the current floating action mode! Expected null"
         This makes that class not to execute the rest of the code and hence the FloatingAction is never created!
         I wish the the author of FloatingActionMode class gave me a method to just stop showing it. menu.clear()
         is supposed to do it, but doesn't do.
         */

            mode.finish();  // menu.close(); menu.clear();
            return false;
        }

        public boolean onActionItemClicked(ActionMode mode, MenuItem item) { return false; }
    });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-24
    • 1970-01-01
    • 2011-09-10
    • 2014-11-28
    • 2021-02-17
    • 1970-01-01
    • 2013-01-05
    • 1970-01-01
    相关资源
    最近更新 更多