Skip to content

[Android] Implemented UseMaterial3 build property and provided basic M3 styles#33074

Merged
PureWeen merged 6 commits intodotnet:mainfrom
NirmalKumarYuvaraj:fix-33073
Dec 23, 2025
Merged

[Android] Implemented UseMaterial3 build property and provided basic M3 styles#33074
PureWeen merged 6 commits intodotnet:mainfrom
NirmalKumarYuvaraj:fix-33073

Conversation

@NirmalKumarYuvaraj
Copy link
Contributor

@NirmalKumarYuvaraj NirmalKumarYuvaraj commented Dec 9, 2025

Description of Change

This pull request introduces the foundation for Material Design 3 (M3) support in .NET MAUI for Android. The changes allow developers to opt into Material Design 3 via a new MSBuild property, provide runtime detection of the Material version, and add the necessary Android resources and styles for M3. By default, apps continue to use Material Design 2 to maintain backward compatibility.

Material Design 3 opt-in and configuration:

  • Added a new MSBuild property UseMaterial3 (default: false) to allow developers to opt into Material Design 3 for Android. Internal build properties are set based on this value, and a build log message informs developers which Material version is active. (Microsoft.Maui.Controls.Common.targets) [1] [2]
  • The Material Design version is now surfaced as a runtime feature switch (Microsoft.Maui.RuntimeFeature.IsMaterial3Enabled), which is set during the build process if UseMaterial3 is specified. (Microsoft.Maui.Controls.targets, RuntimeFeature.cs) [1] [2] [3]

Runtime and theming support:

  • Introduced MaterialDesignHelper for runtime detection of Material Design 3 enablement, with caching for performance and a method to retrieve the current Material version. (MaterialDesignHelper.cs)
  • Updated MauiMaterialContextThemeWrapper to dynamically select the correct base theme (Material 2 or Material 3) at runtime using the new helper. (MauiMaterialContextThemeWrapper.cs)

Android resource additions for Material Design 3:

  • Added comprehensive Material Design 3 color definitions for both light and dark themes, including compatibility colors for legacy components. (colors-material3.xml)
  • Added Material Design 3 style definitions, including base theme, no action bar variant, action mode, and splash theme. (styles-material3.xml)

Issues Fixed

Fixes #33073

Output

Material 2 Material 3
M2 M3

@github-actions
Copy link
Contributor

github-actions bot commented Dec 9, 2025

🚀 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 -- 33074

Or

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

@dotnet-policy-service dotnet-policy-service bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Dec 9, 2025
@sheiksyedm sheiksyedm marked this pull request as ready for review December 10, 2025 14:12
Copilot AI review requested due to automatic review settings December 10, 2025 14:12
Copy link
Contributor

Copilot AI left a comment

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 introduces foundational support for Material Design 3 (M3) on Android in .NET MAUI. It adds a new MSBuild property UseMaterial3 to allow opt-in to M3, implements a runtime feature switch for detecting M3 enablement, and provides comprehensive M3 Android resources (colors and styles). The default behavior remains Material Design 2 for backward compatibility.

Key Changes:

  • Adds IsMaterial3Enabled runtime feature switch with MSBuild integration
  • Dynamically selects Material 2 or Material 3 themes at runtime in MauiMaterialContextThemeWrapper
  • Provides complete M3 color tokens and style definitions for light/dark themes

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/Core/src/RuntimeFeature.cs Adds IsMaterial3Enabled property to expose M3 feature state at runtime
src/Core/src/Platform/Android/MauiMaterialContextThemeWrapper.cs Updates constructor to conditionally use M3 or M2 base theme based on feature flag
src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.targets Integrates UseMaterial3 MSBuild property with runtime feature switch configuration
src/Core/src/Platform/Android/Resources/values/styles-material3.xml Defines M3 theme hierarchy including base theme, no action bar variant, action mode, and splash theme
src/Core/src/Platform/Android/Resources/values/colors-material3.xml Provides comprehensive M3 color tokens for light/dark themes including primary, secondary, tertiary, surface, and state overlay colors

<resources>
<!-- Material 3 Base Theme (Automatically switches between light/dark) -->
<style name="Maui.Material3.Theme.Base" parent="Theme.Material3.DayNight">
<!-- For .NET 9 we optout of edge to edge enforcement by default -->
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

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

The comment "optout" should be "opt out" (two words). This matches the correct spelling used in the original Material 2 styles file (styles.xml line 6).

Suggested change
<!-- For .NET 9 we optout of edge to edge enforcement by default -->
<!-- For .NET 9 we opt out of edge to edge enforcement by default -->

Copilot uses AI. Check for mistakes.
@sheiksyedm
Copy link
Contributor

/rebase

Copy link
Member

@PureWeen PureWeen left a comment

Choose a reason for hiding this comment

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

@github-project-automation github-project-automation bot moved this from Ready To Review to Changes Requested in MAUI SDK Ongoing Dec 22, 2025
@NirmalKumarYuvaraj
Copy link
Contributor Author

Should we load the material3 theme here if the property is set?

https://github.com/dotnet/maui/blob/main/src/Core/src/Platform/Android/MauiAppCompatActivity.cs#L21-L26

@PureWeen , Updated the app theme based on the material3 flag.

@github-project-automation github-project-automation bot moved this from Changes Requested to Approved in MAUI SDK Ongoing Dec 23, 2025
@PureWeen
Copy link
Member

  • failing tests unrelated

@PureWeen PureWeen merged commit 69613dd into dotnet:main Dec 23, 2025
156 of 162 checks passed
@github-project-automation github-project-automation bot moved this from Approved to Done in MAUI SDK Ongoing Dec 23, 2025
StephaneDelcroix pushed a commit that referenced this pull request Jan 5, 2026
…c M3 styles (#33074)

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Description of Change

<!-- Enter description of the fix in this section -->
This pull request introduces the foundation for Material Design 3 (M3)
support in .NET MAUI for Android. The changes allow developers to opt
into Material Design 3 via a new MSBuild property, provide runtime
detection of the Material version, and add the necessary Android
resources and styles for M3. By default, apps continue to use Material
Design 2 to maintain backward compatibility.

**Material Design 3 opt-in and configuration:**

- Added a new MSBuild property `UseMaterial3` (default: false) to allow
developers to opt into Material Design 3 for Android. Internal build
properties are set based on this value, and a build log message informs
developers which Material version is active.
(`Microsoft.Maui.Controls.Common.targets`)
[[1]](diffhunk://#diff-6d91a62f494b70d0fb3dcd4fd0020ef5f83dcbbc9c8240b5cad98fc1058c6061R14-R36)
[[2]](diffhunk://#diff-6d91a62f494b70d0fb3dcd4fd0020ef5f83dcbbc9c8240b5cad98fc1058c6061R57-R76)
- The Material Design version is now surfaced as a runtime feature
switch (`Microsoft.Maui.RuntimeFeature.IsMaterial3Enabled`), which is
set during the build process if `UseMaterial3` is specified.
(`Microsoft.Maui.Controls.targets`, `RuntimeFeature.cs`)
[[1]](diffhunk://#diff-59cefde4ef74a9adcaff4aa8bc3271bd2d795d2b4214d7d56327b5edcca73c14R354-R357)
[[2]](diffhunk://#diff-0fd447e39a83800f1f629c61f23d5a18a5c4d3d30fa3ecd81dbafbc15eb3a402R30)
[[3]](diffhunk://#diff-0fd447e39a83800f1f629c61f23d5a18a5c4d3d30fa3ecd81dbafbc15eb3a402R151-R158)

**Runtime and theming support:**

- Introduced `MaterialDesignHelper` for runtime detection of Material
Design 3 enablement, with caching for performance and a method to
retrieve the current Material version. (`MaterialDesignHelper.cs`)
- Updated `MauiMaterialContextThemeWrapper` to dynamically select the
correct base theme (Material 2 or Material 3) at runtime using the new
helper. (`MauiMaterialContextThemeWrapper.cs`)

**Android resource additions for Material Design 3:**

- Added comprehensive Material Design 3 color definitions for both light
and dark themes, including compatibility colors for legacy components.
(`colors-material3.xml`)
- Added Material Design 3 style definitions, including base theme, no
action bar variant, action mode, and splash theme.
(`styles-material3.xml`)

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #33073

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->

### Output
| Material 2 | Material 3|
|--|--|
| <img width="1080" height="1920" alt="M2"
src="https://github.com/user-attachments/assets/877c4133-6f08-40da-90c3-d685d9e1b882"
/> | <img width="1080" height="1920" alt="M3"
src="https://github.com/user-attachments/assets/e2cebb4b-8438-4858-b453-414c2e03b504"
/> |
@github-actions github-actions bot locked and limited conversation to collaborators Jan 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

community ✨ Community Contribution material3 partner/syncfusion Issues / PR's with Syncfusion collaboration platform/android

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Implement UseMaterial3 MSBuild property to enable M3 at build time

4 participants