最近经常处理这个,所以直接写成了扩展函数,在kotlin中挺好用的。记录下:
/**
* 隐藏状态栏、虚拟按键
* 锁屏后打开屏幕依旧隐藏 需要配和监听setOnSystemUiVisibilityChangeListener
*/
fun Window.makeFullScreenBottomSheet() {
val uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION.or(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)
.or(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)
.or(View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY)
decorView.systemUiVisibility = uiOptions
addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
}
/**
* 隐藏状态栏、虚拟按键
* 锁屏后打开屏幕虚拟按键会弹出
*/
fun Window.makeFullScreen() {
val uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION.or(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)
.or(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)
.or(View.SYSTEM_UI_FLAG_IMMERSIVE)
decorView.systemUiVisibility = uiOptions
addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
}
/**
* 退出全屏模式
*/
fun Window.exitFullScreen() {
val uiOptions = View.SYSTEM_UI_FLAG_VISIBLE
decorView.systemUiVisibility = uiOptions
clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
}
/**
* 隐藏状态栏
*/
fun Window.hideStatusBar() {
addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
}
/**
* 显示状态栏
*/
fun Window.showStatusBar() {
clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
}
/**
* 只隐藏虚拟按键
*/
fun Window.makeHideNaviBottomSheet() {
val uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION.or(View.SYSTEM_UI_FLAG_IMMERSIVE)
decorView.systemUiVisibility = uiOptions
}
参考文章直接看谷歌的即可:
本站由以下主机服务商提供服务支持:
0条评论