Skip to content

[.NET 11] Fix Material3 failures in net 11 branch - #37342

Merged
kubaflo merged 3 commits into
dotnet:net11.0from
Dhivya-SF4094:fix-material3TestFailure
Aug 13, 2026
Merged

[.NET 11] Fix Material3 failures in net 11 branch#37342
kubaflo merged 3 commits into
dotnet:net11.0from
Dhivya-SF4094:fix-material3TestFailure

Conversation

@Dhivya-SF4094

@Dhivya-SF4094 Dhivya-SF4094 commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Root Cause

Cause PR #35463

  • On Android with Material 3 enabled, the toolbar’s default title and navigation icon colors were being resolved from legacy AppCompat sources instead of the Material 3 theme.
  • GetDefaultTitleTextColor retrieved the color from the AppCompat Toolbar_titleTextColor styleable attribute.
  • GetDefaultNavigationIconColor derived the color from the legacy DrawerArrowDrawable.Color default.
  • The additional GetDefaultForegroundColor() fallback used a hard-coded black/white value based on RequestedTheme, which could override or mask the actual theme-provided color.
  • As a result, the toolbar title and navigation icons could render with an incorrect or low-contrast color that did not match the Material 3 toolbar, contributing to the screenshot test failure.

Description of Change

  • Updated the default toolbar color resolution to use the Material 3 theme’s colorOnSurface attribute while preserving the existing behavior for non-Material 3 themes.
  • GetDefaultTitleTextColor: When RuntimeFeature.IsMaterial3Enabled is enabled, returns a ColorStateList based on colorOnSurface. Otherwise, it continues to use the existing AppCompat Toolbar_titleTextColor lookup.
  • GetDefaultNavigationIconColor: When Material 3 is enabled, returns the theme’s colorOnSurface. Otherwise, it continues to use the existing DrawerArrowDrawable default.
  • Removed the intermediate hard-coded GetDefaultForegroundColor() fallback from the title and navigation icon color paths, allowing the theme-provided color to remain authoritative.
  • Explicitly configured IconColor and BarTextColor values continue to take precedence over these defaults.

GetDefaultForegroundColor() Was Removed

  • The foreground color was not originally part of the toolbar fallback chain. The title text and navigation icon defaults previously relied directly on the theme-provided values (Toolbar_titleTextColor and DrawerArrowDrawable). GetDefaultForegroundColor() was introduced later as an additional fallback in PR [Android] Make system chrome follow MAUI bar colors (opt-in) #35463, so removing it restores the original toolbar behavior.

  • It returned hard-coded Black/White values that do not represent the Material 3 colorOnSurface tonal color. This resulted in foreground colors that were inconsistent with the rest of the Material 3 toolbar.

  • It took precedence over the theme-aware default in the fallback chain. Because it was evaluated earlier, it could short-circuit the resolution process and prevent the correct theme color from being applied.

  • Removing it allows the theme-provided value to remain authoritativecolorOnSurface for Material 3 and the existing legacy theme default otherwise. This ensures the toolbar uses the correct platform/theme color and resolves the failing test.

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 37342

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 37342"

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service dotnet-policy-service Bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Aug 12, 2026
@Dhivya-SF4094 Dhivya-SF4094 changed the title [WIP] [.NET 11] Fix Material3 failures in net 11 branch [.NET 11] Fix Material3 failures in net 11 branch Aug 12, 2026
@sheiksyedm
sheiksyedm marked this pull request as ready for review August 13, 2026 11:29
@sheiksyedm
sheiksyedm requested review from kubaflo and a lite review from Copilot August 13, 2026 11:29
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts Android toolbar default foreground color resolution when Material 3 is enabled, aiming to fix screenshot test failures caused by pulling title/navigation icon colors from legacy AppCompat sources and by a hard-coded black/white fallback introduced in PR #35463.

Changes:

  • For Material 3, resolves default toolbar title text and navigation icon colors from the theme’s colorOnSurface.
  • Removes the intermediate hard-coded GetDefaultForegroundColor() fallback from title/navigation color resolution.
  • Stops using the removed fallback for overflow icon color (now only IconColor/BarTextColor influence it).
Suppressed comments (1)

src/Controls/src/Core/Platform/Android/Extensions/ToolbarExtensions.cs:279

  • context.GetThemeAttrColor(Resource.Attribute.colorOnSurface) returns 0 when the attribute isn’t found (src/Core/src/Platform/Android/ContextExtensions.cs:221-247). If Material3 is enabled via feature switch but the theme doesn’t define colorOnSurface, this will set the navigation icon color to fully transparent. Recommend treating 0 as “not resolved” and falling back to the existing DrawerArrowDrawable default.
			if (RuntimeFeature.IsMaterial3Enabled)
			{
				return context.GetThemeAttrColor(Resource.Attribute.colorOnSurface);
			}

Comment on lines +254 to +258
if (RuntimeFeature.IsMaterial3Enabled)
{
var colorContext = context is null
? null
: ColorStateList.ValueOf(new global::Android.Graphics.Color(context.GetThemeAttrColor(Resource.Attribute.colorOnSurface)));
@kubaflo
kubaflo merged commit c3ae7c5 into dotnet:net11.0 Aug 13, 2026
7 of 31 checks passed
@github-actions github-actions Bot added this to the .NET 11.0-preview7 milestone Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

material3 partner/syncfusion Issues / PR's with Syncfusion collaboration platform/android

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants