Created
February 3, 2020 08:41
-
-
Save VladislavTitov/601276c04f099320f59caf044debb607 to your computer and use it in GitHub Desktop.
This file contains 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
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