android显示状态栏隐藏导航栏代码

  • Post author:
  • Post category:其他


/**
     * 显示状态栏, 隐藏虚拟按键
     */
    public void hideBottomUIMenu() {
        //隐藏虚拟按键,并且全屏
        if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower api
            if (getWindow() != null) {
                View v = getWindow().getDecorView();
                if (v != null) {
                    v.setSystemUiVisibility(View.GONE);
                }
            }
        } else if (Build.VERSION.SDK_INT >= 19) {
            int uiOptions =
                    View.SYSTEM_UI_FLAG_IMMERSIVE
                            |View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                            |View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                            |View.SYSTEM_UI_FLAG_VISIBLE;

            if (getWindow() != null) {
                //for new api versions.
                View decorView = getWindow().getDecorView();
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    getWindow().setNavigationBarColor(Color.TRANSPARENT); //设置虚拟按键的背景颜色
                    getWindow().setStatusBarColor(Color.TRANSPARENT); //设置虚拟按键的背景颜色
                }
                if (decorView != null) {
                    decorView.setSystemUiVisibility(uiOptions);
                }
            }
        }
    }



版权声明:本文为weixin_43841938原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。