android动态显示和隐藏status bar(通知栏)

1,在Activity的onCreate中设置:

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

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

2,在需要显示和隐藏的时候调用:

 1     private void hideStatusBar() {

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

 3         attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;

 4         getWindow().setAttributes(attrs);

 5     }

 6 

 7     private void showStatusBar() {

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

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

10         getWindow().setAttributes(attrs);

11     }

即可。

你可能感兴趣的:(android)