关闭该上下文操作栏时导航。抽屉被触发 [英] Dismiss the Contextual Action Bar When Nav. Drawer is Toggled

查看:151
本文介绍了关闭该上下文操作栏时导航。抽屉被触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

href="http://developer.android.com/design/patterns/navigation-drawer.html" rel="nofollow">官方页面导航抽屉设计模式规定的

The official page for the Navigation Drawer design pattern states:

有时候,用户将的状态下上下文操作栏   (CAB)出现,而不是应用程序的操作栏。这通常发生   当用户选择文本或选择后一个多个项目   preSS和保持手势。虽然CAB是可见的,你还是应该   允许用户打开使用边缘刷卡导航抽屉。   然而,替换标准的操作栏上的CAB而导航抽屉是打开的。当用户关闭抽屉,   重新显示CAB。

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.

不过,研究我似乎无法找到一种方法,解雇的语境操作栏里面后,我的

But after researching I can't seem to find a way to "dismiss" the Contextual Action Bar inside my

@Override
public void onDrawerOpened(View drawerView) {
    // ... My Code ...
}

方法。

在我的情况下,CAB(与复制,粘贴等选项),当用户选择在活动从的EditText 文本可能会出现这本身就显示导航。抽屉。

In my case a CAB (with copy, paste, etc. options) may appear when a user selects text from an EditText in an Activity which itself displays a Nav. Drawer.

我见过的<一个href="http://stackoverflow.com/questions/21288278/hiding-contexual-action-bar-while-navigation-drawer-is-open">this问题+答案,但它并没有完全解决我的问题,因为它是关系到一个自定义ActionMode。我怎样才能开除的CAB - 一,显示了当用户选择文本时 - 导航抽屉被触发?

I've seen this question+answer but it doesn't quite fix my problem as it's related to a custom ActionMode. How can I "dismiss" the CAB - the one that shows up when a user selects text - whenever the navigation drawer is toggled?

推荐答案

这是可能的。你必须抓住一个参照 ActionMode 创建时,和 ActionMode.Callback 活动

It is possible. You have to grab a reference to the ActionMode when it is created, and the ActionMode.Callback in your Activity:

@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 ActionMode.Callback

Then when your drawer opens/closes, finish the ActionMode or start a new ActionMode from the ActionMode.Callback:

@Override
public void onDrawerOpened(View drawerView) {
    if (mActionMode != null) {
        mActionMode.finish();
    }
}

@Override
public void onDrawerClosed(View drawerView) {
    if (mActionModeCallback != null) {
        startActionMode(mActionModeCallback);
    }
}

这篇关于关闭该上下文操作栏时导航。抽屉被触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆