设置导航栏的颜色透明
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="LibTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:navigationBarColor" tools:targetApi="lollipop">#00000000</item>
</style>
</resources>
activity配置此theme
然后使用以下方法全屏和取消全屏,不会出现导航栏闪一下白色再变成透明
// 全屏。包括隐藏虚拟导航栏
open fun fullScreen(){
val uiOptions = (//0x00000008 or
View.SYSTEM_UI_FLAG_FULLSCREEN
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
or View.SYSTEM_UI_FLAG_IMMERSIVE
or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
//or 0x00008000
)
window.decorView.systemUiVisibility = uiOptions
}
// 取消全屏
open fun notfullScreen(){
val decorView = window.decorView
// public static final int STATUS_BAR_TRANSPARENT = 0x00000008;
// public static final int NAVIGATION_BAR_TRANSPARENT = 0x00008000;
val uiOptions = (//0x00000008 or
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
// or 0x00008000
// or View.NAVIGATION_BAR_TRANSPARENT
)
decorView.systemUiVisibility =uiOptions
}
···