How do Android's new Toolbar and the Contextual Action Bar work together? [duplicate]
Asked Answered
F

1

9

I'm redesigning my current app roughly following Chris Bane's excellent intro here. One thing struck me, though:

If I set the new v7-appcompat Toolbar as actionbar replacement via setSupportActionBar() and derive my theme from Theme.AppCompat.Light.NoActionBar, then the contextual action bar (CAB) will still pop up and push my contents, including the Toolbar, down:

Now, I could try to make the CAB overlay my Toolbar, but I figured the UI (basically the metrics and placement) of the back button and text of the CAB don't match the Toolbar either (as seen in the image), so I wonder if there is rather a "CAB" mode in the Toolbar implementation so that the Toolbar could take over this role as well?

Fenske answered 21/10, 2014 at 7:45 Comment(0)
W
31

You need to set the following in your theme:

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

This will make the action mode overlay for content view, and therefore your Toolbar.

Wier answered 21/10, 2014 at 9:29 Comment(2)
Many thanks for the pointer, Chris! As I thought, overlaying is the solution. However, as you can see on the screenshot above, there are several visual issues: (1) The back button that dismisses the CAB is placed more on the right than the one from the toolbar, (2) there is a light bar left of "Textauswahl", and (3) the CAB seems to be a few dp smaller in height than the Toolbar (for which I use attr/actionBarSize). Is this expected or are these visual glitches that will be fixed?Fenske
What is to be done if we set some height to the toolbar separate from wrap_content , then the CAB is not able to overlay the toolbar completely.how can we set the width of CAB then.Catalectic

© 2022 - 2024 — McMap. All rights reserved.