Hiding the Navigation Bar
2015-12-11 10:58
267 查看
https://developer.android.com/training/system-ui/navigation.html
This lesson describes how to hide the navigation bar, which was introduced inAndroid 4.0 (API level 14).
Even though this lesson focuses on hiding thenavigation bar, you should design your app to hide the status barat the same time, as described in
Hiding the Status Bar.Hiding the navigation and status bars (while still keeping them readily accessible)lets the content use the entire display space, thereby providing a more immersiveuser experience.
Figure 1. Navigation bar.
hides boththe navigation bar and the status bar:
Note the following:
With this approach, touching anywhere on the screen causes the navigation bar (and status bar) to reappear and remain visible. The user interaction causes the flags to be be cleared.
Once the flags have been cleared, your app needs to reset them if youwant to hide the bars again. See
Responding to UI Visibility Changes for adiscussion of how to listen for UI visibility changes so that your app canrespond accordingly.
Where you set the UI flags makes a difference. If you hide the system bars in your activity's
The method
Navigating away from the view causes flags set with
may also need to use
When you use this approach, it becomes your responsibility to ensure that critical partsof your app's UI don't end up getting covered by system bars. For morediscussion of this topic, see the
Hiding the Status Bar lesson.
Next: Using Immersive Full-Screen Mode
This lesson describes how to hide the navigation bar, which was introduced inAndroid 4.0 (API level 14).
Even though this lesson focuses on hiding thenavigation bar, you should design your app to hide the status barat the same time, as described in
Hiding the Status Bar.Hiding the navigation and status bars (while still keeping them readily accessible)lets the content use the entire display space, thereby providing a more immersiveuser experience.
Figure 1. Navigation bar.
Hide the Navigation Bar on 4.0 and Higher
You can hide the navigation bar on Android 4.0 and higher using theSYSTEM_UI_FLAG_HIDE_NAVIGATIONflag. This snippet
hides boththe navigation bar and the status bar:
View decorView = getWindow().getDecorView(); // Hide both the navigation bar and the status bar. // SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as // a general rule, you should design your app to hide the status bar whenever you // hide the navigation bar. int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN; decorView.setSystemUiVisibility(uiOptions);
Note the following:
With this approach, touching anywhere on the screen causes the navigation bar (and status bar) to reappear and remain visible. The user interaction causes the flags to be be cleared.
Once the flags have been cleared, your app needs to reset them if youwant to hide the bars again. See
Responding to UI Visibility Changes for adiscussion of how to listen for UI visibility changes so that your app canrespond accordingly.
Where you set the UI flags makes a difference. If you hide the system bars in your activity's
onCreate()method and the user presses Home, the system bars will reappear. When the user reopens the activity,
onCreate()won't get called, so the system bars will remain visible. If you want system UI changes topersist as the user navigates in and out of your activity, set UI flags in
onResume()or
onWindowFocusChanged().
The method
setSystemUiVisibility()only has an effect if the view you call it from is visible.
Navigating away from the view causes flags set with
setSystemUiVisibility()to be cleared.
Make Content Appear Behind the Navigation Bar
On Android 4.1 and higher, you can set your application's content to appear behindthe navigation bar, so that the content doesn't resize as the navigation bar hides andshows. To do this, useSYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION.You
may also need to use
SYSTEM_UI_FLAG_LAYOUT_STABLEto help your app maintain astable layout.
When you use this approach, it becomes your responsibility to ensure that critical partsof your app's UI don't end up getting covered by system bars. For morediscussion of this topic, see the
Hiding the Status Bar lesson.
Next: Using Immersive Full-Screen Mode
相关文章推荐
- Intent是只能在Activity之间传递数据吗? 大神解答
- 微信JS-SDK选择相册或拍照并上传PHP实现
- 坑爹的Maven
- 选择使用Zepto的原因
- 存储过程详解
- ListView工作原理
- eclipse中常用的快捷键
- 4.storm中的拓扑示例(进程/线程/任务)
- 最全Pycharm教程(19)——Pycharm编辑器功能之代码折叠
- SQL Server 创建约束图解 唯一 主键
- 图像主结构的提取方法
- C语言词法及语法定义-ANTLR
- https
- Android缩放drawable
- 编译opencv文件
- 在myeclipse工具中执行maven build异常 -Dmaven.multiModuleProjectDirectory system property is not set. Check $
- 拓扑排序(topological sort)
- java nio
- Ipad项目中用到的UIModalPresentationFormSheet,点击阴影部分dismiss 当前presented的controller
- hive shell执行命令报错:Specified key was too long; max key length is 767 bytes