// Step 1: Import necessary classes
import android.os.Build
import android.os.Bundle
import android.view.View
import android.view.Window
import android.view.WindowManager
import androidx.appcompat.app.AppCompatActivity
class YourActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Step 2: Set content view for the activity
setContentView(R.layout.activity_your_layout)
// Step 3: Check if the Android version is Lollipop or higher
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// Step 4: Get the window object from the current activity
val window: Window = window
// Step 5: Set the status bar color
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
window.statusBarColor = resources.getColor(R.color.your_color_resource)
// Optional: If you want to change the navigation bar color as well
// window.navigationBarColor = resources.getColor(R.color.your_navigation_color_resource)
}
}
}