/** * 启动全屏 */ private void FullScreen() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { //5.x开始需要把颜色设置透明,否则导航栏会呈现系统默认的浅灰色 Window window = this.getWindow(); final View decorView = window.getDecorView(); final int option = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; window.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); decorView.setSystemUiVisibility(option); decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() { @Override public void onSystemUiVisibilityChange(int i) { if ((i & View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) == 0) { decorView.setSystemUiVisibility(option); } else { } } }); // window.setStatusBarColor(Color.TRANSPARENT); } else { Window window = this.getWindow(); WindowManager.LayoutParams attributes = window.getAttributes(); int flagTranslucentStatus = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; int flagTranslucentNavigation = WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION; attributes.flags |= flagTranslucentStatus; window.setAttributes(attributes); } } } /* 退出全屏 */ private void quitFullScreen(){ final WindowManager.LayoutParams attrs = getWindow().getAttributes(); attrs.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN); getWindow().setAttributes(attrs); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); }
android 动态实现全屏
最新推荐文章于 2024-04-29 11:26:32 发布