Android 控制屏幕全屏,标题栏,导航栏,布局属性

//方法1

//通过View类设置系统ui可见性.

        int[] mCheckFlags = new int[] {View.SYSTEM_UI_FLAG_LOW_PROFILE,//隐藏系统状态栏的信息,只保留时间和电量信息,并使状态栏变暗
            View.SYSTEM_UI_FLAG_FULLSCREEN,//全屏,隐藏状态栏
            View.SYSTEM_UI_FLAG_HIDE_NAVIGATION,
            View.SYSTEM_UI_FLAG_IMMERSIVE, 
            View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY,
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE, 
            View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN,//让窗口的布局全屏,顶部会向上延伸,但是会被系统状态栏覆盖
            View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
    };

    View.setSystemUiVisibility();

//设置标题栏透明:

private void setTranslucentStatus(boolean on) {
        Window win = getWindow();
        WindowManager.LayoutParams winParams = win.getAttributes();
        final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
        if (on) {
            winParams.flags |=  bits;
        } else {
            winParams.flags &= ~bits;
        }
        win.setAttributes(winParams);
    }

//设置底部导航栏透明:

    private void setTranslucentNavigation(boolean on) {
        Window win = getWindow();
        WindowManager.LayoutParams winParams = win.getAttributes();
        final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION;
        if (on) {
            winParams.flags |=  bits;
        } else {
            winParams.flags &= ~bits;
        }
        win.setAttributes(winParams);
    }

//设置全屏


private void setFullscreen(boolean on) {
        Window win = getWindow();
        WindowManager.LayoutParams winParams = win.getAttributes();
        final int bits = WindowManager.LayoutParams.FLAG_FULLSCREEN;
        if (on) {
            winParams.flags |=  bits;
        } else {
            winParams.flags &= ~bits;
        }
        win.setAttributes(winParams);
    }

//设置布局不变,布局不会随着状态栏透明而拉伸

    private void setOverscan(boolean on) {
        Window win = getWindow();
        WindowManager.LayoutParams winParams = win.getAttributes();
        final int bits = WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN;
        if (on) {
            winParams.flags |=  bits;
        } else {
            winParams.flags &= ~bits;
        }
        win.setAttributes(winParams);
    }

你可能感兴趣的:(Android笔记)