Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,15 @@ void ConnectAndInitialize()
// Connect using the adapter (which properly implements IStackNavigationView via page delegation)
_stackNavigationManager.Connect(_navigationViewAdapter, _navigationContainer);

// Apply dark/light background to the navigation container when the page has no explicit
// Background, matching old ShellPageContainer constructor behavior.
// We set it on the container (not the page's platform view) because the page's handler
// hasn't been created yet at this point — StackNavigationManager creates it asynchronously.
// The page view is transparent by default, so the container background shows through.
// Apply background to the navigation container when the page has no explicit Background.
// Matches old ShellPageContainer constructor behavior.
if (_rootPage is IView view && view.Background is null && _navigationContainer is not null)
{
var context = _mauiContext!.Context!;
bool isDark = Controls.Application.Current?.RequestedTheme == ApplicationModel.AppTheme.Dark;
int bgColor = isDark
? AndroidX.Core.Content.ContextCompat.GetColor(context, global::Android.Resource.Color.BackgroundDark)
: AndroidX.Core.Content.ContextCompat.GetColor(context, global::Android.Resource.Color.BackgroundLight);
int bgColor = RuntimeFeature.IsMaterial3Enabled
? GetMaterial3Background(context)
: GetResourceBackground(context, isDark);
_navigationContainer.SetBackgroundColor(new global::Android.Graphics.Color(bgColor));
}

Expand Down Expand Up @@ -545,6 +542,20 @@ protected override void Dispose(bool disposing)
}
base.Dispose(disposing);
}

static int GetMaterial3Background(Context context)
{
// Material3 colorSurface automatically adapts to light/dark theme.
// The theme resolution happens in GetThemeAttrColor based on the active theme.
return ContextExtensions.GetThemeAttrColor(context, Resource.Attribute.colorSurface);
}

static int GetResourceBackground(Context context, bool isDark)
{
return isDark
? AndroidX.Core.Content.ContextCompat.GetColor(context, global::Android.Resource.Color.BackgroundDark)
: AndroidX.Core.Content.ContextCompat.GetColor(context, global::Android.Resource.Color.BackgroundLight);
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,7 @@ protected override AView CreatePlatformElement()
var context = MauiContext?.Context
?? throw new InvalidOperationException("MauiContext.Context cannot be null");

// Resolve ?attr/actionBarSize to match the old XML layout height.
// The old shellsectionlayout.axml used android:layout_height="?attr/actionBarSize"
// for the TabLayout. Using wrap_content would make tabs ~48dp instead of 56dp,
// shifting all content below and causing visual regressions.
var actionBarSizeAttribute = new int[] { global::Android.Resource.Attribute.ActionBarSize };
var typedArray = context.ObtainStyledAttributes(actionBarSizeAttribute);
int actionBarHeight = typedArray.GetDimensionPixelSize(0, LP.WrapContent);
typedArray.Recycle();
int actionBarHeight = context.GetActionBarHeight();

_contentTabLayout = new TabLayout(context)
{
Expand Down
Loading