Most of us know by now how to hide the notification bar, it is one of the first things that needs to be done when creating a game or and imersive app. There are 2 popular solutions to this, but buth behave slightly differently and 1 little fix could can make your app behave better.
Adding that simple line to your ‘application’ or ‘activity’ in your AndroidManifest.xml
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
or in your activity before you call setContentView()
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
Both solutions can have your view being laid out below(not behind) the notification bar in certain situations. Usually everything works great when your app is launched, or a new activity is created. You may only see the issue when returning to your app from a screen that has the notification bar visible, most commonly this happens when you back out of a web view or ad, back to your app.
The first option above can result in your view being shifted down the height of the notification bar. This is because it starts getting laid out before the notification bar animates off the screen. This is the worst case as any content on the bottom of your layout my be shifted at least partially off the bottom of the screen. The second option, as it is written, is better; because it will reshift the view after the notification bar animates off the screen. So functionally, everything is fine with the second option; but what about something better?
There is an option to make your view lay out BEHIND the notification bar. Then it gets revealed as the notification bar animates off the screen. This is generally much more visually appealing than having your view layout, then shift up into position; and is obviously better than the option that leaves your view shifted off the screen.
And the best thing about this fix is that it is just as simple as hiding the notification bar was in the first place. Just add the following, also before you call setContentView().
getWindow().setFlags( WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS );
Ratan says:
This Works Wonderfully