您的位置:首页 > 移动开发 > Android开发

当 Activity 以全屏模式运行时,如何允许 Android 系统状态栏在顶层出现,而不迫使 Activity 重新布局让出空间

2014-04-24 10:55 567 查看
当 Activity 以全屏模式运行时,如何允许 Android 系统状态栏在顶层出现,而不迫使 Activity

重新布局让出空间

private void hideStatusBar() {

WindowManager.LayoutParams attrs = getWindow().getAttributes();

attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;

getWindow().setAttributes(attrs);

}

private void showStatusBar() {

WindowManager.LayoutParams attrs = getWindow().getAttributes();

attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;

getWindow().setAttributes(attrs);

}

关键是,在做了该Activity的全屏设置的前提下,还要在onCreate()方法中加入如下语句:

getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);

getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

此方案我已经试过了,可行,且不会导致Activity重排。

此方案是我Google搜索出来的,网址如下:

Hacking Android: Show/hide status bar in fullscreen application

感谢他!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐