20

I know that I can make the ActionBar overlay using requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY)
and can toggle/show the status bar in my screen (by switching between FLAG_FULLSCREEN and FLAG_FORCE_NOT_FULLSCREEN).
This works great. However, I don't want my layout moving when I toggle the status bar.

I know that I can make the status bar "overlay" (albeit not transparently) the content using:

WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS

This works also great, except for the (expected) consequence that, when using an ActionBar, the ActionBar gets half cut off - half of it is under the status bar basically.

So I am wondering, is there a way to "move the ActionBar down" by the status bar's height in this case?
I know that in worse case, I can do this with a custom view that lives within the layout, but I rather not do this (want to benefit from the ActionBar).

thanks!

Nickolaus
  • 4,785
  • 4
  • 38
  • 60
ahmedre
  • 1,684
  • 1
  • 14
  • 18

4 Answers4

4

so apparently, you can do this in Jellybean. google includes two examples in the api docs. here is a link: http://developer.android.com/reference/android/view/View.html#setSystemUiVisibility%28int%29

summary: use setSystemUiVisibility on a view to toggle visibility (on jellybean+).

ahmedre
  • 1,684
  • 1
  • 14
  • 18
  • How can this be achieved in ICS, any idea? – N.R.S.Sowrabh Nov 01 '12 at 11:07
  • 1
    without using your own actionbar (custom implementation that doesn't set in the window decoration area), i don't know if this is doable. the closest you can get is David Scott's answer below. – ahmedre Dec 02 '12 at 07:27
3

It's not perfect, but this is how I have achieved what you want:

In onCreate:

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

Then:

private void hideStatusBar() {
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);

}

private void showStatusBar() {
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

}

I also have a style on the activity with the following:

 <style name="readingStyle" parent="@style/Theme.Sherlock">
     <item name="android:windowActionBarOverlay">true</item>  
     <item name="windowActionBarOverlay">true</item>       
 </style> 

Your activity will shift down when the status bar shows, but I don't think it's too noticeable.

David Scott
  • 1,666
  • 12
  • 22
  • thanks David - unfortunately, this was already what i had - i was trying to prevent the activity from shifting down. i guess the only way to do it is to use a custom layout as an actionbar and just set the clock to overlay instead of actually using a real actionbar :( – ahmedre Jun 07 '12 at 06:03
  • your method `hideStatusBar()` works more robust than `setSystemUiVisibility` in conjunction with the ActionBar from compatibility package – OneWorld Aug 26 '15 at 09:03
0

Why you dont make it in the Manifest

android:theme="@android:style/Theme.Black.NoTitleBar"

than you have no statusbar and more space for the Actionbar??

Phil
  • 2,396
  • 2
  • 18
  • 15
  • thanks, but since this is a reading app, i want the user to know the time when they tap the screen, and want my layout to be full screen otherwise. – ahmedre May 04 '12 at 08:55
0

Put this method in onCreate() method activity:

getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);

refer: link

Community
  • 1
  • 1
huu duy
  • 2,049
  • 21
  • 31