How To Hide Status Bar In Android?
In this post we are going learn how to hide status bar (and navigation optionally), by hiding status bar you can have more space to show your contact and provide more immersive user experience.
Note : If you hide status bar then you must hide action bar with it.
Figure.1 show app with visible status bar.
Figure.1 show app with visible status bar.
Figure 1.Visible Status Bar.
Figure 2. show app with hidden status bar, you can see that action bar also hidden, you should never show action bar when status bar is hidden.
Figure 2. Hidden Status Bar.
You can hide status bar on Android 4.1 and higher using setSystemUiVisibility()
setSystemUiVisibility() set the flag at individual view level and those settings aggregated to window level. If you set UI flag using setSystemUiVisibility() then you get more granular control over system bar then using WindowManager flags.
Follow code snippet hide status bar.
You must remember following points when you use this approach.
- If UI flag cleared by any activity(i.e. navigating away from activity).Your app must set them again if you want to hide status bar again.
- Where you set system UI flag matter most.If you hide System Bars in activity's onCreate() method and if user press home button then system bar will appear again.If user reopen app then onCreate() will not called.so system bars remain visible.If you want to persist as user navigate in and out of your activity.Then set UI flags in onWindowFocusChanged() or OnResume().
- The setSystemUiVisibility() method works only if you call it from view which is visible.
- If User navigate away then UI flags set with setSystemUiVisibility() is cleared.
No comments:
Post a Comment