码迷,mamicode.com
首页 > 移动开发 > 详细

android开发全屏切换代码,记录一下

时间:2020-05-16 16:57:50      阅读:70      评论:0      收藏:0      [点我收藏+]

标签:screen   hid   support   show   nbsp   attribute   开发   action   manager   

private void tryFullScreen(boolean fullScreen) {
  if (activity instanceof AppCompatActivity) {
    ActionBar supportActionBar = ((AppCompatActivity) activity).getSupportActionBar();
    if (supportActionBar != null) {
      if (fullScreen) {
        supportActionBar.hide();
      } else {
        supportActionBar.show();
      }
    }
  }
  setFullScreen(fullScreen);
}

private void setFullScreen(boolean fullScreen) {
  if (activity != null) {
    WindowManager.LayoutParams attrs = activity.getWindow().getAttributes();
    if (fullScreen) {
      attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
      activity.getWindow().setAttributes(attrs);
      activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
    } else {
      attrs.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
      activity.getWindow().setAttributes(attrs);
      activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
    }
  }
}

 

android开发全屏切换代码,记录一下

标签:screen   hid   support   show   nbsp   attribute   开发   action   manager   

原文地址:https://www.cnblogs.com/yongfengnice/p/12900761.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!