Skip to content

Instantly share code, notes, and snippets.

@whalemare
Created October 9, 2018 03:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whalemare/f9715b70a9ea18f0a5d6b9c9a01268d4 to your computer and use it in GitHub Desktop.
Save whalemare/f9715b70a9ea18f0a5d6b9c9a01268d4 to your computer and use it in GitHub Desktop.
Android set status bar light
@TargetApi(Build.VERSION_CODES.M)
fun Window.setLightStatusBar(light: Boolean) {
var flags = decorView.systemUiVisibility
if (light && (flags and View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR == View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR)) {
return
} else if (!light && (flags and View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR) != View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR) {
return
}
val colorRes = if (light) {
flags = flags or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
R.color.statusBarLight
} else {
flags = flags xor View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
R.color.primaryDark
}
decorView.systemUiVisibility = flags
statusBarColor = ContextCompat.getColor(context, colorRes)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment