简体   繁体   English

在EditText上调用setCustomSelectionActionModeCallback()之后,如何修复上下文菜单栏功能(复制/粘贴等)?

[英]How to fix Context Menu Bar functions (copy/paste etc) after calling setCustomSelectionActionModeCallback() on EditText?

I'm writing Notepad App in which I've got slider menu showing some text format panel. 我正在编写记事本应用程序,其中有显示一些文本格式面板的滑块菜单。 I toggle view of this panel when user tries to select some text, so I've implemented my menu-toggling code into my EditText's setCustomSelectionActionModeCallback() which looks like this: 当用户尝试选择一些文本时,我切换此面板的视图,因此我已将菜单切换代码实现到EditText的setCustomSelectionActionModeCallback()中,如下所示:

private void manageContextMenuBar(EditText editText) {

    editText.setCustomSelectionActionModeCallback(new ActionMode.Callback() {

        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            return true;
        }
        // There menu is hidden
        public void onDestroyActionMode(ActionMode mode) {
            if (findViewById(R.id.sliderMenu).getVisibility() == View.VISIBLE) {
                findViewById(R.id.sliderMenu).setVisibility(View.GONE);
            }
        }
        // There menu shows up
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {

            if (findViewById(R.id.sliderMenu).getVisibility() == View.GONE) {
                findViewById(R.id.sliderMenu).setVisibility(View.VISIBLE);
            }
            return true;
        }

        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {


            return true;
        }
    });
}

When I long click on text my format menu shows up, and also software context menu with paste/copy/cut button on it. 当我长时间单击文本时,将显示格式菜单,以及带有粘贴/复制/剪切按钮的软件上下文菜单。

The problem is that because of my "Overriding" context menu functions, they stopped working. 问题是由于我的“覆盖”上下文菜单功能,它们停止了工作。 I can click the buttons, but they doesn't work. 我可以单击按钮,但是它们不起作用。

I hope You will understand my problem Any help will be appreciated :) 希望您能理解我的问题,将不胜感激:)

You should return false from onActionItemClicked method. 您应该从onActionItemClicked方法return false This way when you click on those menu items Android uses the default actions. 这样,当您单击这些菜单项时,Android将使用默认操作。

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

From the onActionItemClicked method Documentation: Returns: true if this callback handled the event, false if the standard MenuItem invocation should continue. onActionItemClicked方法文档中: Returns: true if this callback handled the event, false if the standard MenuItem invocation should continue.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Swing App中使用JTextField剪切/复制/粘贴的全局上下文菜单? - Global context menu for Cut/Copy/Paste with JTextField in Swing App? 粘贴后如何格式化android EditText? - How to format android EditText after paste? 复制粘贴选项未出现在EditText中 - Copy paste option not appearing for EditText 单击按钮后,如何将文本从alertdialog的EditText复制并粘贴到活动的EditText中? - How do I copy and paste text from EditText of alertdialog to EditText of my activity, on button click? Java - 如何挂钩到Mac OS上的“复制和粘贴”菜单 - Java - How to hook into the Copy and Paste menu on the Mac OS SWT:具有复制/粘贴功能的表 - SWT: Table with copy/paste functions 如何在editText中禁用“复制/剪切/粘贴/”工具栏,但仍然有光标选择一些文本? - How to disable “copy/cut/paste/” toolbar in editText, but still have cursor to select some text? 如何使用位于导航栏应用程序子布局上的“findViewById()”方法修复对 EditText 实例的访问? - How to fix access an instance of EditText with "findViewById()" method located on a sub layout in navigation bar app? 为大量JTextField提供复制/粘贴菜单 - Providing copy/paste menu to a large number of JTextFields 调用notifyDataSetChanged()后丢失EditText值; - Losing EditText Value After Calling notifyDataSetChanged();
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM