Created
April 19, 2019 13:06
-
-
Save piyush-malaviya/d1500e619f2f7e5f0460f2269f3fb10c to your computer and use it in GitHub Desktop.
Make Status bar transparent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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