|
31 | 31 | import android.content.Context; |
32 | 32 | import android.content.SharedPreferences; |
33 | 33 | import android.graphics.Color; |
| 34 | +import android.graphics.drawable.ColorDrawable; |
34 | 35 | import android.os.Build; |
35 | 36 | import android.os.Bundle; |
36 | 37 | import android.os.StrictMode; |
37 | 38 | import android.util.Log; |
38 | | -import android.util.TypedValue; |
39 | 39 | import android.view.View; |
40 | 40 |
|
41 | 41 | import androidx.annotation.NonNull; |
42 | 42 | import androidx.annotation.Nullable; |
| 43 | +import androidx.core.content.ContextCompat; |
43 | 44 | import androidx.core.graphics.Insets; |
44 | 45 | import androidx.core.view.OnApplyWindowInsetsListener; |
45 | 46 | import androidx.core.view.ViewCompat; |
|
48 | 49 | import androidx.preference.PreferenceManager; |
49 | 50 |
|
50 | 51 | import net.kollnig.missioncontrol.BuildConfig; |
| 52 | +import net.kollnig.missioncontrol.DetailsActivity; |
51 | 53 | import net.kollnig.missioncontrol.R; |
52 | 54 |
|
53 | 55 | import org.acra.ACRA; |
@@ -121,28 +123,43 @@ public void onCreate() { |
121 | 123 | registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() { |
122 | 124 | @Override |
123 | 125 | public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) { |
| 126 | + if (activity.getClass() == DetailsActivity.class) |
| 127 | + return; |
| 128 | + |
124 | 129 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) { |
125 | | - View content = activity.findViewById(android.R.id.content); |
| 130 | + android.widget.FrameLayout content = activity.findViewById(android.R.id.content); |
| 131 | + |
| 132 | + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity); |
| 133 | + boolean dark = prefs.getBoolean("dark_theme", false); |
| 134 | + |
| 135 | + // On Android 15+, setStatusBarColor is ignored |
| 136 | + // Set window background to primary color - this shows behind the status bar |
| 137 | + int primaryColor = ContextCompat.getColor(activity, R.color.colorPrimary); |
| 138 | + activity.getWindow().setBackgroundDrawable(new ColorDrawable(primaryColor)); |
| 139 | + |
| 140 | + // Set status bar icons to light (white) since our background is dark |
| 141 | + View decor = activity.getWindow().getDecorView(); |
| 142 | + WindowCompat.getInsetsController(activity.getWindow(), decor).setAppearanceLightStatusBars(false); |
| 143 | + WindowCompat.getInsetsController(activity.getWindow(), decor).setAppearanceLightNavigationBars(!dark); |
| 144 | + |
126 | 145 | ViewCompat.setOnApplyWindowInsetsListener(content, new OnApplyWindowInsetsListener() { |
127 | 146 | @NonNull |
128 | 147 | @Override |
129 | 148 | public WindowInsetsCompat onApplyWindowInsets(@NonNull View v, @NonNull WindowInsetsCompat insets) { |
130 | 149 | Insets bars = insets.getInsets(WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout() | WindowInsetsCompat.Type.ime()); |
131 | 150 |
|
132 | | - TypedValue tv = new TypedValue(); |
133 | | - activity.getTheme().resolveAttribute(R.attr.colorPrimaryDark, tv, true); |
134 | | - |
135 | 151 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity); |
136 | 152 | boolean dark = prefs.getBoolean("dark_theme", false); |
137 | 153 |
|
138 | | - activity.getWindow().getDecorView().setBackgroundColor(tv.data); |
139 | | - content.setBackgroundColor(dark ? Color.parseColor("#ff121212") : Color.WHITE); |
| 154 | + // Apply padding to android.R.id.content for system bars |
| 155 | + v.setPadding(bars.left, bars.top, bars.right, bars.bottom); |
140 | 156 |
|
141 | | - int actionBarHeight = Util.dips2pixels(56, activity); |
142 | | - View decor = activity.getWindow().getDecorView(); |
143 | | - WindowCompat.getInsetsController(activity.getWindow(), decor).setAppearanceLightStatusBars(false); |
144 | | - WindowCompat.getInsetsController(activity.getWindow(), decor).setAppearanceLightNavigationBars(!dark); |
145 | | - v.setPadding(bars.left, bars.top + actionBarHeight, bars.right, bars.bottom); |
| 157 | + // Set background on the actual layout (first child), not on the content frame |
| 158 | + // This way the padding area shows the window background (primary color) |
| 159 | + if (content.getChildCount() > 0) { |
| 160 | + View child = content.getChildAt(0); |
| 161 | + child.setBackgroundColor(dark ? Color.parseColor("#ff121212") : Color.WHITE); |
| 162 | + } |
146 | 163 |
|
147 | 164 | return insets; |
148 | 165 | } |
|
0 commit comments