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.
Set Actionbar overlay mode at runtime in Android
Asked Answered
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.
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 : ( –
Crary © 2022 - 2024 — McMap. All rights reserved.
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 – MetageActionBar
(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. – Crary