11/*
2- * Copyright (c) 2020, Gluon
2+ * Copyright (c) 2020, 2025, Gluon
33 *
44 * This program is free software: you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
2929
3030import android .app .Activity ;
3131import android .content .Context ;
32+ import android .graphics .drawable .ColorDrawable ;
3233import android .os .Build ;
3334import android .util .Log ;
35+ import android .view .View ;
3436import android .view .Window ;
3537import android .view .WindowManager ;
3638
@@ -45,7 +47,7 @@ public DalvikStatusBarService(Activity activity) {
4547 }
4648
4749 private void setColor (final int color ) {
48- if (Build .VERSION .SDK_INT < Build .VERSION_CODES .LOLLIPOP ) {
50+ if (Build .VERSION .SDK_INT < Build .VERSION_CODES .LOLLIPOP ) { // < 21
4951 Log .e (TAG , "StatusBar service is not supported for the current Android version" );
5052 return ;
5153 }
@@ -62,9 +64,27 @@ private void setColor(final int color) {
6264 @ Override
6365 public void run () {
6466 Window window = activity .getWindow ();
65- window .clearFlags (WindowManager .LayoutParams .FLAG_TRANSLUCENT_STATUS );
66- window .addFlags (WindowManager .LayoutParams .FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS );
67- window .setStatusBarColor (color );
67+ if (Build .VERSION .SDK_INT <= Build .VERSION_CODES .UPSIDE_DOWN_CAKE ) { // <= 34
68+ window .addFlags (WindowManager .LayoutParams .FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS );
69+ // make status bar transparent
70+ window .setStatusBarColor (0x00000000 );
71+ // paint window
72+ window .setBackgroundDrawable (new ColorDrawable (color ));
73+ } else { // >= 35
74+ View decorView = window .getDecorView ();
75+
76+ // Get insets, before applying the color, as it will reset them
77+ int top = decorView .getPaddingTop ();
78+ int right = decorView .getPaddingRight ();
79+ int bottom = decorView .getPaddingBottom ();
80+ int left = decorView .getPaddingLeft ();
81+
82+ // Apply color
83+ decorView .setBackground (new ColorDrawable (color ));
84+
85+ // Restore insets
86+ decorView .setPadding (left , top , right , bottom );
87+ }
6888 }
6989 });
7090 }
0 commit comments