android-ktx icon indicating copy to clipboard operation
android-ktx copied to clipboard

Expose an easier way to enable or disable a system UI flag

Open rock3r opened this issue 7 years ago • 3 comments

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.

rock3r avatar Feb 05 '18 21:02 rock3r

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.

JakeWharton avatar Feb 05 '18 21:02 JakeWharton

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 :)

rock3r avatar Feb 05 '18 21:02 rock3r

Window.setFullScreen(): Window = this.apply { 
    decorView.systemUiVisibility = decorView.systemUiVisibility or View.SYSTEM_UI_FLAG_FULLSCREEN 
}

This approach allows chaining of flag application

Edward608 avatar Feb 06 '18 10:02 Edward608