最近做视频方面的项目,碰到视频需要全屏播放,因此需要将状态栏隐藏,并且退出全屏是状态栏又需要显示出来;代码如下:
//隐藏状态栏
WindowManager.LayoutParams lp = mActivity.getWindow().getAttributes();
lp.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
mActivity.getWindow().setAttributes(lp);
mActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
//显示状态栏
WindowManager.LayoutParams attr = mActivity.getWindow().getAttributes();
attr.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
mActivity.getWindow().setAttributes(attr);
mActivity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);