赞
踩
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { val insetsController = this.window.insetsController // 隐藏状态栏 insetsController?.hide(WindowInsets.Type.statusBars()) // 隐藏导航栏 insetsController?.hide(WindowInsets.Type.navigationBars()) // 隐藏标题栏 supportActionBar?.hide() // 设置状态栏是透明的 this.window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) // 设置导航栏是透明的 this.window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) this.window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) // 解决隐藏状态栏时,顶部出现黑长条问题,该属性可以让布局内容延伸到状态栏显示 this.window.attributes.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES } else { this.window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) this.window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) this.window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN) this.window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) }
override fun onWindowFocusChanged(hasFocus: Boolean) {
super.onWindowFocusChanged(hasFocus)
// 判断是否有焦点
if (hasFocus && Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
val decorView = window.decorView
decorView.setSystemUiVisibility(
android.view.View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or android.view.View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
)
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。