Skip to content

Instantly share code, notes, and snippets.

@VladislavTitov
Created February 3, 2020 08:41
Show Gist options
  • Save VladislavTitov/601276c04f099320f59caf044debb607 to your computer and use it in GitHub Desktop.
Save VladislavTitov/601276c04f099320f59caf044debb607 to your computer and use it in GitHub Desktop.
fun updateStatusBar(activity: Activity, lightStatusBar: Boolean) =
activity.window.apply {
when {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M -> {
if (lightStatusBar) {
decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
} else {
decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
}
statusBarColor = ResourcesCompat.getColor(activity.resources, android.R.color.transparent, null)
}
Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP -> {
decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
if (lightStatusBar) {
addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
} else {
clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
}
statusBarColor = ResourcesCompat.getColor(activity.resources, android.R.color.transparent, null)
}
else -> {
// nothing, just black status bar on API 19 & 20
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment