https://developer.android.com/training/system-ui/navigation.html

 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);

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 to persist as the user navigates in and out of your activity, set UI flags in onResume() or onWindowFocusChanged().

https://developer.android.com/training/system-ui/immersive.html

 // This snippet hides the system bars.
private void hideSystemUI() {
// Set the IMMERSIVE flag.
// Set the content to appear under the system bars so that the content
// doesn't resize when the system bars hide and show.
mDecorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
| View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
| View.SYSTEM_UI_FLAG_IMMERSIVE);
} // This snippet shows the system bars. It does this by removing all the flags
// except for the ones that make the content appear under the system bars.
private void showSystemUI() {
mDecorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}

Note: If you like the auto-hiding behavior of IMMERSIVE_STICKY but need to show your own UI controls as well, just use IMMERSIVE combined with Handler.postDelayed() or something similar to re-enter immersive mode after a few seconds.

Current Requirement:

  • Hide navigation bar on startup
  • Auto hide navigation bar (IMMERSIVE_STICKY + poseDelayed() )

Implementation:

     //////////////////////////////////////////////////////////////////////////
public void hideNavigationBar() {
int uiFlags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
| View.SYSTEM_UI_FLAG_FULLSCREEN; // hide status bar if( android.os.Build.VERSION.SDK_INT >= 19 ){
uiFlags |= 0x00001000; //SYSTEM_UI_FLAG_IMMERSIVE_STICKY: hide navigation bars - compatibility: building API level is lower thatn 19, use magic number directly for higher API target level
} else {
uiFlags |= View.SYSTEM_UI_FLAG_LOW_PROFILE;
} getWindow().getDecorView().setSystemUiVisibility(uiFlags);
} //////////////////////////////////////////////////////////////////////////
@Override
protected void onCreate (Bundle savedInstanceState) {
...
hideNavigationBar();
super.onCreate(savedInstanceState);
...
} //////////////////////////////////////////////////////////////////////////
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if( hasFocus ) {
hideNavigationBar();
}
}

Note: postDelayed is not yet added, because on tested devices, navigation bar will auto hide for some secs.

Add postDelayed() event to manully auto hide nav bar if needed.


on some system, after volume key's pressed, navigation bar is shown & never hidden until keys on navi bar is pressed.

hard fix:

     //////////////////////////////////////////////////////////////////////////
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
super.onKeyUp(keyCode, event);
if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)){
this.hideNavigationBar();
}
return false;
}

[工作积累] Android: Hide Navigation bar 隐藏导航条的更多相关文章

  1. Android hide Navigation bar

    最近一个app需要隐藏Navigation bar导航栏. 参考文档 http://blog.csdn.net/zwlove5280/article/details/52823128 http://j ...

  2. iOS 隐藏导航条分割线

    // 导航条分割线 @property (nonatomic, strong) UIView *navSeparateView; // 获取导航条分割线 UIView *backgroundView ...

  3. 把 Navigation Bar 下面那条线删掉的最简单的办法! — By: 昉

    系统默认的 Navigation Bar 下面一直有条线,翻尽了文档却没找到能把它弄走的相关接口,处女座的简直木法忍啊有木有!!!! 研究了一下navigationBar下的子视图,原来只需要几行代码 ...

  4. 【转】iOS隐藏导航条1px的底部横线

    默认情况下会有这条线 第一种方法: 1 2 3 4 5 6 UINavigationBar *navigationBar = self.navigationController.navigationB ...

  5. [工作积累] android 中添加libssl和libcurl

    1. libssl https://github.com/guardianproject/openssl-android 然后执行ndk-build 2.libcurl 源代码组织结构, 下面的mak ...

  6. [工作积累] Android dynamic library & JNI_OnLoad

    Bionic libc doesn't load dependencies for current .so file (diff from Windows or Linux) so a explici ...

  7. [工作积累] Android system dialog with native callback

    JNI: invoke java dialog with native callback: store native function address in java, and invoke nati ...

  8. iOS隐藏导航条1px的底部横线

    第二种方法:1)声明UIImageView变量,存储底部横线 @implementation MyViewController { UIImageView *navBarHairlineImageVi ...

  9. Android开发关闭虚拟按钮、底部导航条

    在Android开发中,遇到了一系列大大小小的问题,其中一个就是屏蔽底部实体键,我找了很多的博客也尝试了许许多多的方法,但始终不能屏蔽 HOME键,后来看见一篇博客说在Android 4.0以后,屏蔽 ...

随机推荐

  1. php循环创建目录

    代码取自thinkphp中: function mk_dir($dir, $mod = 0777) { if(!is_dir($dir) || mkdir($dir, $mod)) { if(!mk_ ...

  2. 升级Mac X Mavericks MacMiv 无法启动

    今天把Mac 系统升级到了 Mac X Mavericks ,确实有不少的惊喜.虽然体验不出Mac X Mavericks拥有更强的性能/更好的电池表现,但是新版的Safari浏览器的提供了更方便的主 ...

  3. delphi 基础之三 编写和调用dll文件

    delphi 编写和调用dll文件   Windows 的执行文件可以划分为两种形式程序和动态连接库 (DLLs).一般程序运行是用.EXE文件,但应用程序有时也可以调用存储在DLL的函数. 在如下几 ...

  4. jquery 点击页面其他地方实现隐藏菜单功能

    1.给页面文档添加一个点击事件函数,在函数内实现隐藏菜单功能. $('html').click(function(){//Hide the menus if visible});//用$(docume ...

  5. 自适应游标共享技术02(一个简单的例子来走近ACS)

    为了不让其他因素干扰实验,参数设置如下: optimizer_mode=ALL_ROWS(使用CBO) optimizer_features_enable=11.2.0.3(使用最新的优化参数) op ...

  6. 使用shell从DB2数据库导出数据

    使用shell脚本根据输入的用户名,数据库名,密码从DB2数据库导出数据 (1)a.sh脚本如下 #!/usr/bin/bash read -p "please input your DBN ...

  7. RAP开发入门-搭建RAP开发环境(一)

    ps:补充 RAP (Remote Application Platform) 官网地址eclipse.org/rap 1.下载IDE http://www.eclipse.org/downloads ...

  8. JSAPI_Ticket签名

    1.微信 JS 接口签名校验工具 2.具体开发 2.1 获取access_token,然后jsapi_ticket /** * 获取access_token,然后jsapi_ticket */ pri ...

  9. Python pexpect出现错误‘module have no attribute "spawn" 解决办法

    今天我遇到了这个错误,现在将错误总结如下: 1.首先查询一下自己的操作系统,pexpect中的spawn()和run()仅仅运行在POSIX系统上,在WINDOWS下是没有这两个东西的,在官网http ...

  10. GraphLab面向机器学习的并行框架『针对图数据处理模型』

    最近在做文本处理知识的梳理,关注了CMU提出的GraphLab开源分布式计算系统 这是关于GraphLab的PPT:Distributed GraphLab『 http://cheng-qihang- ...