How To Hide Navigation Bar In Android ?
In this post we are gonna learn how to hide Navigation Bar.Navigation bar was introduced in Android 4.0 (API level 14). When ever you hide navigation bar you should also hide status bar at the same time.You can learn how to hide status bar HERE.When you hide navigation bar (and status bar) using this approach your app content can use full display space,and user can easily access navigation bar (and status bar).
Figure 1. Navigation Bar
You can hide navigation bar using the SYSTEM_UI_FLAG_HIDE_NAVIGATION. As you can see in following code snipped.(In this example we will hide both navigation bar and status bar)
Following are some points which you need to keep in mind when using this approach.
- When you hide navigation bar (and status bar) using this approach , if user touch anywhere on screen then navigation bar (and status bar) will reappear and not hide again automatically.User interaction clears those flags.
- Once flags have cleared by any cause,your app needs to set them again if you want to hide system bars again.
- If you set those flag in activity's onCreate() method and user tab on home then system bars will appears and not hide when user came back in app. Activity's onCreate() method will not call when user reopen app.You can set those flags in onResume() or in onWindowFocusChanged() when you again want to hide system bar user reopen app.
- setSystemUiVisibility() method only works if it's called from visible view.
- Any system ui flag set with setSystemUiVisibility() will cleared if user navigate away from app.
No comments:
Post a Comment