如何隐藏 EditText 的文本选择句柄的动作弹出窗口

How to hide ActionPopupWindow of Text Selection Handler of EditText

实际上我想在用户单击 + 图标时隐藏 ActionPopupWindow(具有 SELECT ALL、CLIPBOARD 选项的弹出窗口)。

当用户点击文本选择处理程序(气泡)时出现 ActionPopupWindow(当用户点击 EditText 中的文本时出现)。

我尝试使用 EditText 的 setTextIsSelectable() 方法,但它无法始终如一地工作。

我们将不胜感激任何帮助或指导。

UPDATE: To hide the Popup already opened and showing on the screen, you need to clear focus of the current EditText or focus on other view when you clicked the plus button. See the example below:

iconPlus.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        yourEditText.clearFocus();
    }
});

如果您希望弹出窗口永远不会出现在第一位,有很多方法可以做到。

最简单的方法是禁用长按和选择功能:

yourEditText.setLongClickable(false);
yourEditText.setTextIsSelectable(false);

第二个是 覆盖 编辑文本上的操作回调操作:

    yourEditText.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;
        }
    });

您可以根据自己的情况单独使用或一起使用。

您还可以查看 here

中的其他选项