status bar color android kotlin
To change the status bar color in Android using Kotlin, you can follow these steps:
- Get the Window object of the current Activity by calling the
window
property:
val window = this.window
- Set the status bar color by calling the
statusBarColor
property of the Window object and passing in the desired color:
window.statusBarColor = ContextCompat.getColor(this, R.color.statusBarColor)
Note: Replace R.color.statusBarColor
with the color resource you want to use.
- To ensure that the status bar icons are visible on the colored background, you can set the system UI flags using the
decorView
property of the Window object:
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
- If you want to remove the translucent status bar, you can clear the
FLAG_TRANSLUCENT_STATUS
flag using theclearFlags()
method of the Window object:
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
And that's it! By following these steps, you can change the status bar color in Android using Kotlin.