[英]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.