在activity中动态设置显示和隐藏通知栏

来源:互联网 发布:cba数据库 编辑:程序博客网 时间:2024/06/06 02:06

安卓想要设置全屏模式方法有:

1.在清单文件中去配置theme:

2.需要在onCreate()方法中去设置
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
            WindowManager.LayoutParams.FLAG_FULLSCREEN);并且需要在setContentView()之前

如果我们需要在初始化之后再去设置全屏模式,这时候这种方法就不能满足我们的需求了:
解决方法:

private void full(boolean enable) {
        if (enable) {

//设置全屏
            WindowManager.LayoutParams lp = getWindow().getAttributes();
            lp.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
            getWindow().setAttributes(lp);
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
        } else {

//取消全屏
            WindowManager.LayoutParams attr = getWindow().getAttributes();
            attr.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
            getWindow().setAttributes(attr);
            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
        }

    }

0 0
原创粉丝点击