14

How do I set the actionbar mode at runtime to not-overlay or overlay with the content at runtime? I tried using getWindow().requestFeature(Window.FEATURE_ACTIONBAR_OVERLAY) but it doesn't allow to set the mode after calling setContentView(). This can be done, as I have seen it being done in the Youtube app.

N.R.S.Sowrabh
  • 725
  • 13
  • 30
  • Hi Sowrabh, did you find any solution? – Wayne Dec 19 '12 at 04:51
  • 1
    No luck @Wayne. The best I could do is to set the actionbar overlay mode to `Window.FEATURE_ACTIONBAR_OVERLAY` always and then set the Y-coordinate of the whole view to the bottom of the actionbar when needed. Not a very clean solution though – N.R.S.Sowrabh Dec 19 '12 at 04:53
  • 1
    Oh thanks you, that may be a workaround :D. But it will be nice if we know how Youtube did it :D – Wayne Dec 19 '12 at 05:16
  • [Possible duplicate](http://stackoverflow.com/q/6749261/420015) – adneal Jul 01 '13 at 07:02
  • That question doesn't ask about changing the actionbar overlay mode at runtime. All it asks is how to get an actionbar in a full screen app. – N.R.S.Sowrabh Jul 04 '13 at 13:50
  • 1
    I'm pretty sure YouTube is faking us out, and on the 'full screen' video, they have a fake `ActionBar` (totally guessing based on what I am seeing). On your phone, if you go into landscape and minimize the video, then slowly drag the video to full screen, when the top of it hits the actionbar the actionbar hides / animates up. – xbakesx Feb 08 '14 at 21:59

1 Answers1

5

Although not necessarily exactly what you're looking for, one decent workaround would be to create a spacer view at the top of the content that is the same height as the ActionBar (android:layout_height="?android:actionBarSize"). When you want overlay mode enabled, set the spacer's visibility to View.GONE, when you want it disabled, set it to View.VISIBLE.

aravance
  • 89
  • 1
  • 9
  • This is definitely a valid work-around. The overlay-ness of the ActionBar is a style, and those have to be set before they are shown and don't change at runtime, so a work-around seems necessary. An issue with this work around is that getting the height of the actionbar isn't as simple as stated in the answer, you have to `getActionBar().getHeight()` after it's visible because the "stacked" actionbar (think actionbar tabs on a phone in portrait) isn't included in android:actionBarSize and because we don't know all the variables Android uses to decide whether or not stacked is shown : ( – xbakesx Feb 08 '14 at 21:55