I am working on using the newly added Toolbar that was introduced in Lollipop and the AppCompat-v7 library. I followed this guide on setting up the Toolbar I noticed that when you invoke something that will bring up the contextual ActionBar (such as highlighting text for copy/pasting), that it will push the Toolbar down on the page. You can see what I am talking about in the image at the bottom of the page:
So, essentially, I set it up like this. I have the Toolbar defined in an xml file that I use with include tags:
<!-- Rest of view -->
// On Create method of activity:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
Solution: use the windowActionModeOverlay property. Set this in your theme:
and the actionmode will be shown over the action bar instead of pushing it down. (If you're not using the latest AppCompat then you need to add the "android:" prefix to the property). It basically lets AppCompat know that you have a toolbar located in the top of the screen and that it should draw the ActionMode on top of it.
I ran into the same problem. No matter what theme I set, it always pushes down the Toolbar I set as ActionBar. I tried with and without the support library, but it didn't matter.
Unfortunately I was not able to fix it so I have built a workaround instead. In my
onCreateActionMode I hide the action bar:
onDestroyActionModeI show it again:
The hiding/showing happens so quickly it is not noticeable on my test devices. There is of course a downside: although the enter-animation still works, the exit-animation of the contextual action bar gets lost because the Toolbar immediately pops over it. But until we come across a better solution I guess we are stuck with this.
(My Activity is actually extending a custom
BaseActivity class which has a method called
getActionBarToolbar(), taken from the Google I/O 2014 app source code, so I can easily get fetch the Toolbar:
BaseActivity activity = (BaseActivity) getActivity(); activity.getActionBarToolbar().setVisibility(View.GONE);
Too bad the I/O app does not use the contextual action bar.)