Skip to content

Commit b890d24

Browse files
committed
chore: Adjust theming of Android status bar based on app theme
1 parent b6a7f12 commit b890d24

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

src/Uno.UI/UI/Xaml/Application.Android.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Microsoft.UI.Xaml.Controls.Primitives;
1111
using Windows.UI.ViewManagement;
1212
using Colors = Microsoft.UI.Colors;
13+
using Uno.UI.Xaml.Controls;
1314

1415
namespace Microsoft.UI.Xaml;
1516

@@ -31,12 +32,5 @@ static partial void StartPartial(ApplicationInitializationCallback callback)
3132
/// </remarks>
3233
private DateTimeOffset GetSuspendingOffset() => DateTimeOffset.Now.AddSeconds(5);
3334

34-
partial void ApplySystemOverlaysTheming()
35-
{
36-
var requestedTheme = InternalRequestedTheme;
37-
38-
StatusBar.GetForCurrentView().ForegroundColor = requestedTheme == ApplicationTheme.Dark
39-
? Colors.White
40-
: Colors.Black;
41-
}
35+
partial void ApplySystemOverlaysTheming() => NativeWindowWrapper.Instance?.ApplySystemOverlaysTheming();
4236
}

src/Uno.UI/UI/Xaml/Window/Native/NativeWindowWrapper.Android.cs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
using Android.Runtime;
44
using Android.Util;
55
using Android.Views;
6-
using AndroidX.AppCompat.App;
76
using AndroidX.Core.View;
87
using Uno.Disposables;
98
using Uno.Foundation.Logging;
109
using Uno.UI.Extensions;
1110
using Windows.ApplicationModel.Core;
1211
using Windows.Foundation;
13-
using Windows.Graphics;
1412
using Windows.Graphics.Display;
1513
using Windows.UI.Core;
1614
using Windows.UI.ViewManagement;
@@ -78,6 +76,7 @@ internal void RaiseNativeSizeChanged()
7876
Bounds = new Rect(default, windowSize);
7977
VisibleBounds = visibleBounds;
8078
Size = new((int)(windowSize.Width * RasterizationScale), (int)(windowSize.Height * RasterizationScale));
79+
ApplySystemOverlaysTheming();
8180

8281
if (_previousTrueVisibleBounds != visibleBounds)
8382
{
@@ -88,7 +87,11 @@ internal void RaiseNativeSizeChanged()
8887
}
8988
}
9089

91-
protected override void ShowCore() => RemovePreDrawListener();
90+
protected override void ShowCore()
91+
{
92+
ApplySystemOverlaysTheming();
93+
RemovePreDrawListener();
94+
}
9295

9396
private (Size windowSize, Rect visibleBounds) GetVisualBounds()
9497
{
@@ -191,6 +194,24 @@ private WindowInsetsCompat GetWindowInsets(Activity activity)
191194
return null;
192195
}
193196

197+
internal void ApplySystemOverlaysTheming()
198+
{
199+
if ((int)Android.OS.Build.VERSION.SdkInt >= 35)
200+
{
201+
// In edge-to-edge experience we want to adjust the theming of status bar to match the app theme.
202+
if ((ContextHelper.Current is Activity activity) &&
203+
activity.Window?.DecorView is { FitsSystemWindows: false } decorView)
204+
{
205+
var requestedTheme = Microsoft.UI.Xaml.Application.Current.RequestedTheme;
206+
207+
var insetsController = WindowCompat.GetInsetsController(activity.Window, decorView);
208+
209+
// "appearance light" refers to status bar set to light theme == dark foreground
210+
insetsController.AppearanceLightStatusBars = requestedTheme == Microsoft.UI.Xaml.ApplicationTheme.Light;
211+
}
212+
}
213+
}
214+
194215
private Size GetWindowSize()
195216
{
196217
if (ContextHelper.Current is not Activity activity)

src/Uno.UWP/UI/ViewManagement/StatusBar/StatusBar.Android.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ internal void UpdateSystemUiVisibility()
143143
}
144144
}
145145

146-
// A bit confusingly, "appearance light" refers to light theme, so in dark foreground is used!
146+
// A bit confusingly, "appearance light" refers to light theme, so dark foreground is used!
147147
insetsController.AppearanceLightStatusBars = _foregroundType == StatusBarForegroundType.Dark;
148148
}
149149
}

0 commit comments

Comments
 (0)