status bar color android kotlin

To change the status bar color in Android using Kotlin, you can follow these steps:

  1. Get the Window object of the current Activity by calling the window property:
val window = this.window
  1. 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.

  1. 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
  1. If you want to remove the translucent status bar, you can clear the FLAG_TRANSLUCENT_STATUS flag using the clearFlags() 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.