What is a clean way to hide and show ActionBar without a glitchy animation

Viewed 80

I have an activity with a tabbed ViewPager, containing five pages. The tabs are shown in the bottom of the screen.

Four of these pages are supposed to show custom ActionBars, one isn't.

I know when a page is chosen and can react to it by calling Actionbar.show() and Actionbar.hide() respectively. However, this makes the bottom of my activity glitch up and down for a second, because the layout seems to be redrawn or something. For a second I can see a "white background behind my actual background color" and all of my underlying Views "jump" until they settle down and get to the correct position.

As explained by this answer. However, the proposed solution is to use android:windowActionBarOverlay. This solves the problem with the glitch, but creates another one, where the pages that are supposed to show an ActionBar have part of their layout be cut off, because it is now "underneath" the ActionBar

Using actionBar.setShowHideAnimationEnabled as suggested in this answer doesn't help either. The bottom of my activity still glitches.

I know I could use the approach from the first answer and just add a margin to the top of the respective pages that are supposed to show an action bar to move the content that's supposed to be visible lower. However this approach seems a little hacky to me, because the way I would do this would involve getting the height from the ActionBar and adding it to the top of those pages appropriate layout elements at runtime, because I don't know the exact height of the ActionBar, which varies from device to device.

I need a clean solution to hide and show the ActionBar when showing a specific page, without the Activity glitching around.

PS: I would like to solve this without a third party library

Edit

Using androidx.appcompat.app.AppCompatActivity and getSupportActionBar()

0 Answers
Related