Android 显示隐藏状态栏

2016-05-25  本文已影响0人  糖糖_Fun

Android 显示隐藏状态栏,小说阅读界面要用到

/** 
  * 显示隐藏状态栏,全屏不变,只在有全屏时有效 
  * @param enable 
  */
private void setStatusBarVisibility(boolean enable) {
    WindowManager.LayoutParams lp = getWindow().getAttributes();
    if (enable) {
        lp.flags |= WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN;
    } else {
        lp.flags &= (~WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
    }
    getWindow().setAttributes(lp);
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
/**
 * 设置是否全屏
 * @param enable
 */
private void setFullScreen(boolean enable) {
    WindowManager.LayoutParams lp = getWindow().getAttributes();
    if (enable) {
        lp.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
    } else {
        lp.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }
    getWindow().setAttributes(lp);
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
上一篇 下一篇

猜你喜欢

热点阅读