43

I have implemented my own viewgroup for my application. Using actionbar is not an option for various reasons so in my viewgroup I have my own "actionbars" one on top and one in the bottom. Image 1 illustrates my current layout.

Image 1

As you can see there are two edittexts in the layout and everything looks ok.

However when the user selects some text in any of the edittexts the contextual actionmode bar is shown. Image 2 illustrates this.

Image 2

When this happens actionmode bar "pushes" down my entire layout in order to get its space. In tablets and other large screen devices this is OK but in smaller devices and especially with the soft keyboard visible the remaining height is too small (in landscape orientation is unusable).

What I want to do is actionmode bar to overlay my layout instead of pushing it down as shown in Image 3.

Image 3

Is that possible?

ChD Computers
  • 3,135
  • 3
  • 23
  • 33

3 Answers3

57

Just add <item name="android:windowActionModeOverlay">true</item> to your style.

marijnvdwerf
  • 923
  • 11
  • 14
  • 2
    O.M.G. This one was of the type "How can anyone miss that?". Worked like a charm, thank you very much!!! – ChD Computers Jul 21 '13 at 21:29
  • 17
    i didn't work for me. i am using "Theme.AppCompat.Light.NoActionBar" and a toolbar – user987760 May 13 '15 at 10:00
  • i have same issue but this answer didnt help. i have a listview and i show cab(contextual action bar ) when user selects an item. so if i select first item i the list , the cab is displayed and item s checkbox is checked but the view is pushed up. The last page of list will be visible and i have to scroll up to see the first item that was selected. Further selecting items do not push view as cab is already present. – png Jan 05 '16 at 07:49
  • 8
    Dudes, it didn't work for me neither until i notice that i was testing on API 23 and i set that in `values`and not in `values-21` too.. – Mino Feb 22 '16 at 14:05
  • 15
    @user987760 if use with AppCompatActivity, you should use `true` ( no `android:` prefix) – don't panic Feb 14 '17 at 03:43
  • @lazybug Thank you for your valuable comment. – MSS Nov 03 '17 at 16:04
  • @lazybug you are an MVP. shall i buy you a beer? – EdgeDev Feb 07 '19 at 13:34
38

To use windowActionModeOverlay with appcompat toolbar,use

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

to your style.

Giru Bhai
  • 14,370
  • 5
  • 46
  • 74
  • 2
    Maybe this should be turned into the accepted answer instead. I don't think AppCompat even was a thing when I posted the original answer in '13. – marijnvdwerf Feb 23 '16 at 22:30
3

This can also be done programmatically using:

 getWindow().requestFeature(Window.FEATURE_ACTION_MODE_OVERLAY);
Dean Wild
  • 5,886
  • 3
  • 38
  • 45