Created
October 9, 2018 03:06
-
-
Save whalemare/f9715b70a9ea18f0a5d6b9c9a01268d4 to your computer and use it in GitHub Desktop.
Android set status bar light
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
@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