如何使上下文ActionMode栏覆盖了appcompat-V7工具栏,但不能导航抽屉里?上下文、工具栏、抽屉里、appcompat

2023-09-04 10:08:27 作者:此男子已醉

我有一个应用程序栏和导航抽屉的活动。应用栏将使用新的工具栏类从appcompat-V7版本的库21 +实现,而抽屉式导航栏将显示在它的前面。

I have an activity with an app bar and a navigation drawer. The app bar is implemented using the new Toolbar class from appcompat-v7 library version 21.+, and the navigation drawer is displayed in front of it.

活动包含一个列表视图可以选择的项目,所以我表现出上下文操作栏(CAB)。它是通过调用启动:

The activity contains a list view with items which can be selected, so I am showing a contextual action bar (CAB). It is started by calling:

ActionBarActivity.startSupportActionMode(android.support.v7.view.ActionMode.Callback callback)

默认情况下,CAB插入工具栏,而不是覆盖在它上面;似乎CAB将只覆盖了真正的动作条在默认情况下。作为展this回答的CAB正确叠加时,这个主题属性设置工具栏:

By default, the CAB is inserted above the Toolbar instead of overlaying it; it seems that the CAB will only overlay the true ActionBar by default. As show in this answer, the CAB correctly overlays the Toolbar when this theme property is set:

<item name="windowActionModeOverlay">true</item>

但是,这也使得CAB覆盖的抽屉式导航,根据的材料设计规格的。主要的Andr​​oid的设计文档还是建议隐藏导航抽屉打开时,CAB,并再次显示它在关闭时,和this可以做来修复的问题,但它不应该是必要的。作为编写的材料设计规范没有指定的导航抽屉打开时CAB应该被隐藏,而由于资产净值抽屉应该打开了驾驶室里,隐藏了CAB实际上会是一个视觉干扰。

But this also makes the CAB overlay the navigation drawer, which is incorrect according to the Material design specs. The main Android design docs still recommend hiding the CAB when the navigation drawer is opened and showing it again when closed, and this could be done to "fix" the problem, but it should not be necessary. As-written, the Material design specs don't specify that the CAB should be hidden when the nav drawer opens, and because the nav drawer should open over the CAB, hiding the CAB would in fact be a visual distraction.

有没有什么办法可以显示导航抽屉中的CAB前面时,仍然有它覆盖了工具栏?

Is there any way to display the navigation drawer in front of the CAB while still having it overlay the Toolbar?

推荐答案

我可能已经找到了解决方案 - 或者一个简单的解决方法 我有同样的问题,甚至有ListFragment,当 startActionMode()代替内置的 setChoiceMode()。 所以,我看着ListFragment code,我发现 startActionMode()不叫上的活动,而是它的ListView,所以我使用视图尝试。 在我的code现在它显然适用于使用任一片段的Lis​​tView预期:

I might have found a solution - or perhaps a simple workaround. I had the same problem even with a ListFragment, when startActionMode() was used instead of the built-in setChoiceMode(). So I looked into ListFragment code and I found that startActionMode() is not called on the activity but rather on its ListView, so I've tried using a view. In my code now it apparently works as expected using either the fragment ListView:

ActionMode mActionMode = getListView().startActionMode(this);

或使用包含我的片段活动容器:

or using the Activity container that contains my fragment:

View aView = getActivity().findViewById(R.id.container);
ActionMode mActionMode = aView.startActionMode(this);

另外:

现在,后退按钮破坏的操作模式,而之前它没有 的CAB现在可以正确地涵盖了操作栏,同时使用 windowActionModeOverlay 在我的风格只覆盖它的一部分 - 至少在我的情况下 的CAB图标是一个向后的箭头,而不是打勾 - 不知道这意味着什么,虽然 now the back button destroys the action mode whilst before it didn't the CAB now properly covers the Action Bar, whilst using windowActionModeOverlay in my style was covering only part of it - at least in my case the CAB icon is a back arrow rather than a tick - not sure what this means though

说实话,我不知道这背后的原因,所以我不知道该解决方案是如何安全的,但是,对于存在似乎正常工作的时间。 如果任何人有一个更深入的了解,请随时发表评论或编辑。

To be honest I'm not sure about the reasons behind this, so I'm not sure how safe this solutions is, however for the time being seems to work fine. Should anyone have a better understanding please feel free to comment or edit.