diff --git a/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellContentFragment.cs b/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellContentFragment.cs index ad0f11feeada..13855c591379 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellContentFragment.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellContentFragment.cs @@ -9,6 +9,8 @@ using AndroidX.Core.View; using AndroidX.Fragment.App; using Google.Android.Material.AppBar; +using Microsoft.Maui.Controls.Handlers.Compatibility; +using Microsoft.Maui.Graphics; using Microsoft.Maui.Platform; using AndroidAnimation = Android.Views.Animations.Animation; using AnimationSet = Android.Views.Animations.AnimationSet; @@ -136,6 +138,11 @@ public override AView OnCreateView(LayoutInflater inflater, ViewGroup container, _root = inflater.Inflate(Controls.Resource.Layout.shellcontent, null).JavaCast(); + // Set theme-aware background color immediately to prevent white flash during transitions. + // The CoordinatorLayout is inflated without a background color, which can cause + // white flash during fragment transitions when using dark theme. + _root.SetBackgroundColor(ShellRenderer.DefaultBottomNavigationViewBackgroundColor.ToPlatform()); + MauiWindowInsetListener.SetupViewWithLocalListener(_root); var shellContentMauiContext = _shellContext.Shell.Handler.MauiContext.MakeScoped(layoutInflater: inflater, fragmentManager: ChildFragmentManager); diff --git a/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellItemRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellItemRenderer.cs index e75fdf86a5ce..1b7a010664ee 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellItemRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellItemRenderer.cs @@ -13,6 +13,7 @@ using Google.Android.Material.Navigation; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; +using Microsoft.Maui.Controls.Handlers.Compatibility; using Microsoft.Maui.Graphics; using AColor = Android.Graphics.Color; using AView = Android.Views.View; @@ -76,6 +77,14 @@ public override AView OnCreateView(LayoutInflater inflater, ViewGroup container, _navigationArea = PlatformInterop.CreateNavigationBarArea(context, _outerLayout); _bottomView = PlatformInterop.CreateNavigationBar(context, Resource.Attribute.bottomNavigationViewStyle, _outerLayout, this); + // Set theme-aware background colors immediately to prevent white flash during transitions. + // The BottomNavigationView is created with Color.WHITE in PlatformInterop.java, but the + // correct theme-aware color should be applied immediately before any UI is rendered. + // We also set the navigation area background to prevent white flash during fragment transitions. + var themeAwareBackgroundColor = ShellRenderer.DefaultBottomNavigationViewBackgroundColor.ToPlatform(); + _bottomView.SetBackgroundColor(themeAwareBackgroundColor); + _navigationArea.SetBackgroundColor(themeAwareBackgroundColor); + if (ShellItem is null) throw new InvalidOperationException("Active Shell Item not set. Have you added any Shell Items to your Shell?"); diff --git a/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellSectionRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellSectionRenderer.cs index a3f4513ccaf2..865c33b98eb8 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellSectionRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellSectionRenderer.cs @@ -16,6 +16,8 @@ using Google.Android.Material.AppBar; using Google.Android.Material.Tabs; using Microsoft.Extensions.Logging; +using Microsoft.Maui.Controls.Handlers.Compatibility; +using Microsoft.Maui.Graphics; using Microsoft.Maui.Platform; using AToolbar = AndroidX.AppCompat.Widget.Toolbar; using AView = Android.Views.View; @@ -102,6 +104,12 @@ public override AView OnCreateView(LayoutInflater inflater, ViewGroup container, var context = Context; var root = PlatformInterop.CreateShellCoordinatorLayout(context); + + // Set theme-aware background color immediately to prevent white flash during transitions. + // The CoordinatorLayout is created without a background, which can cause white flash + // during fragment transitions when using dark theme. + root.SetBackgroundColor(ShellRenderer.DefaultBottomNavigationViewBackgroundColor.ToPlatform()); + var appbar = PlatformInterop.CreateShellAppBar(context, Resource.Attribute.appBarLayoutStyle, root); MauiWindowInsetListener.SetupViewWithLocalListener(root);