@@ -31,15 +31,42 @@ fun AppCompatActivity.adjustUIForAPILevel35(
3131 window.addSystemBarPaddings()
3232}
3333
34+ /* *
35+ *
36+ * This function provides a unified approach to setting status bar colors across different
37+ * Android versions, with special handling for Android 15 (VANILLA_ICE_CREAM) and above
38+ * where direct status bar color modification is no longer supported.
39+ *
40+ * ## Android Version Compatibility:
41+ *
42+ * ### Android 14 and below (API < 35):
43+ * - Uses the traditional `Window.setStatusBarColor()` method
44+ *
45+ * ### Android 15+ (API 35+):
46+ * - **⚠ IMPORTANT**: Direct status bar color modification is NOT possible
47+ * - Uses a workaround by applying top padding equal to status bar height
48+ * - Sets the view's background color to simulate the desired appearance
49+ * - This is a visual approximation, not actual status bar color change
50+ *
51+ * * @see [Android Documentation](https://developer.android.com/reference/kotlin/android/view/Window#setstatusbarcolor)
52+ * * @see Window.setStatusBarColor (deprecated in API 35)
53+ *
54+ * @param color The desired color as a ColorInt.
55+ *
56+ * @warning On Android 15+, this is a visual workaround only. The actual status bar
57+ * color cannot be modified and will remain transparent with system-managed contrast.
58+ */
3459fun AppCompatActivity.initStatusBar (
3560 @ColorInt color : Int
3661) {
3762 window.decorView.setOnApplyWindowInsetsListener { view, insets ->
38- view.setBackgroundColor(color)
39-
4063 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .VANILLA_ICE_CREAM ) {
4164 val statusBarHeight = insets.getInsets(WindowInsets .Type .statusBars()).top
4265 view.setPadding(0 , statusBarHeight, 0 , 0 )
66+ view.setBackgroundColor(color)
67+ } else {
68+ @Suppress(" DEPRECATION" )
69+ window.statusBarColor = color
4370 }
4471
4572 insets
0 commit comments