android-ktx
android-ktx copied to clipboard
Expose an easier way to enable or disable a system UI flag
This is an extension function I frequently end up writing and using in projects:
@RequiresApi(26)
fun Activity.setNavigationBarStyle() = window.apply {
decorView.systemUiVisibility = decorView.systemUiVisibility or View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
}
(off the top of my head)
The only difference with what I usually end up writing is that this will not handle the API < 26 case (I usually NO-OP in those cases) but instead uses a require API annotation.
This seems too hyper-specific for my taste because it means adding one function for every system UI flag. Exposing an easier way to enable or disable a system UI flag, however, might be more appropriate.
Yeah you have a point. My need is specifically about the navbar, but there's plenty system UI flags that could benefit from a neater way to toggle them. Trust you will find something more generic :)
Window.setFullScreen(): Window = this.apply {
decorView.systemUiVisibility = decorView.systemUiVisibility or View.SYSTEM_UI_FLAG_FULLSCREEN
}
This approach allows chaining of flag application