Skip to content

Instantly share code, notes, and snippets.

@piyush-malaviya
Created April 19, 2019 13: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 piyush-malaviya/d1500e619f2f7e5f0460f2269f3fb10c to your computer and use it in GitHub Desktop.
Save piyush-malaviya/d1500e619f2f7e5f0460f2269f3fb10c to your computer and use it in GitHub Desktop.
Make Status bar transparent
protected fun setStatusBarTranslucent(makeTranslucent: Boolean) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
if (makeTranslucent) {
window.setFlags(
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
)
window.setFlags(
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION
)
setLightStatusBar()
} else {
window.clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION)
clearLightStatusBar()
}
}
}
private fun setLightStatusBar() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
var flags = window.decorView.systemUiVisibility // get current flag
flags = flags or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR // add LIGHT_STATUS_BAR to flag
window.decorView.systemUiVisibility = flags
}
}
private fun clearLightStatusBar() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
var flags = window.decorView.systemUiVisibility // get current flag
flags =
flags and View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.inv() // use XOR here for remove LIGHT_STATUS_BAR from flags
window.decorView.systemUiVisibility = flags
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment