official page for the Navigation Drawer design pattern状态:
Sometimes the user will be in a state where a contextual action bar (CAB) appears instead of the app’s action bar. This typically happens when the user selects text or selects multiple items after a press-and-hold gesture. While the CAB is visible, you should still allow the user to open the navigation drawer using an edge swipe. However, replace the CAB with the standard action bar while the navigation drawer is open. When the user dismisses the drawer, re-display the CAB.
但是经过研究,我似乎找不到一种方法来“关闭”我的
中的上下文操作栏@Override
public void onDrawerOpened(View drawerView) {
// ... My Code ...
}
方法。
在我的例子中,当用户从本身显示导航的 Activity
中的 EditText
选择文本时,可能会出现 CAB(带有复制、粘贴等选项) 。抽屉。
我见过this question+answer但它并不能完全解决我的问题,因为它与自定义 ActionMode 有关。每当切换抽屉导航时,如何“关闭”CAB(用户选择文本时显示的 CAB)?
最佳答案
这是可能的。您必须在创建 ActionMode
时获取对它的引用,并在 Activity
中获取对 ActionMode.Callback
的引用:
@Override
public void onActionModeStarted(ActionMode mode) {
super.onActionModeStarted(mode);
mActionMode = mode;
}
@Override
public void onActionModeFinished(ActionMode mode) {
super.onActionModeFinished(mode);
mActionMode = null;
}
@Override
public ActionMode onWindowStartingActionMode(ActionMode.Callback callback) {
mActionModeCallback = callback;
return super.onWindowStartingActionMode(callback);
}
然后,当您的抽屉打开/关闭时,完成 ActionMode
或从 ActionMode.Callback
启动新的 ActionMode
:
@Override
public void onDrawerOpened(View drawerView) {
if (mActionMode != null) {
mActionMode.finish();
}
}
@Override
public void onDrawerClosed(View drawerView) {
if (mActionModeCallback != null) {
startActionMode(mActionModeCallback);
}
}
关于java - 导航时关闭上下文操作栏。抽屉已切换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23475559/