Search code examples
androidandroid-actionbarcontextual-action-bar

How do Android's new Toolbar and the Contextual Action Bar work together?


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?


Solution

  • 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.