From 0847763c326ab614d437f48c79de2a3bad352535 Mon Sep 17 00:00:00 2001 From: NirmalKumarYuvaraj <97871636+NirmalKumarYuvaraj@users.noreply.github.com> Date: Tue, 9 Dec 2025 18:53:12 +0530 Subject: [PATCH 1/6] implemented build property and styles --- .../Microsoft.Maui.Controls.Common.targets | 43 +++++ .../Microsoft.Maui.Controls.targets | 4 + .../Platform/Android/MaterialDesignHelper.cs | 71 +++++++ .../MauiMaterialContextThemeWrapper.cs | 5 +- .../Resources/values/colors-material3.xml | 178 ++++++++++++++++++ .../Resources/values/styles-material3.xml | 38 ++++ src/Core/src/RuntimeFeature.cs | 9 + 7 files changed, 347 insertions(+), 1 deletion(-) create mode 100644 src/Core/src/Platform/Android/MaterialDesignHelper.cs create mode 100644 src/Core/src/Platform/Android/Resources/values/colors-material3.xml create mode 100644 src/Core/src/Platform/Android/Resources/values/styles-material3.xml diff --git a/src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.Common.targets b/src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.Common.targets index 55462cab2279..8b2318ed2b56 100644 --- a/src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.Common.targets +++ b/src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.Common.targets @@ -11,6 +11,29 @@ '$([MSBuild]::GetTargetPlatformIdentifier($(TargetFramework)))' == 'tizen')">True + + + + false + + + + + + <_MauiAndroidMaterial3Enabled Condition="'$(UseMaterial3)' == 'true'">true + <_MauiAndroidMaterial3Enabled Condition="'$(UseMaterial3)' != 'true'">false + + + <_MauiMaterialDesignVersion Condition="'$(UseMaterial3)' == 'true'">3 + <_MauiMaterialDesignVersion Condition="'$(UseMaterial3)' != 'true'">2 + + false @@ -31,4 +54,24 @@ + + + + + + <_MauiMaterialMessage Condition="'$(UseMaterial3)' == 'true'">Material Design 3 enabled (UseMaterial3=true) + <_MauiMaterialMessage Condition="'$(UseMaterial3)' != 'true'">Material Design 2 (default) - Set UseMaterial3=true to enable Material Design 3 + + + + + + diff --git a/src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.targets b/src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.targets index 0fe1df68c9dd..6eee58090437 100644 --- a/src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.targets +++ b/src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.targets @@ -351,6 +351,10 @@ Condition="'$(_EnableMauiAspire)' != ''" Value="$(_EnableMauiAspire)" Trim="true" /> + diff --git a/src/Core/src/Platform/Android/MaterialDesignHelper.cs b/src/Core/src/Platform/Android/MaterialDesignHelper.cs new file mode 100644 index 000000000000..e77e68dc1024 --- /dev/null +++ b/src/Core/src/Platform/Android/MaterialDesignHelper.cs @@ -0,0 +1,71 @@ +using Android.Content; + +namespace Microsoft.Maui.Platform +{ + /// + /// Helper class for Material Design version detection and configuration on Android. + /// + /// + /// This helper provides runtime detection of whether Material Design 3 is enabled + /// through the UseMaterial3 MSBuild property. The configuration is cached after the + /// first access for performance. + /// + internal static class MaterialDesignHelper + { + private static bool? _isMaterial3Enabled; + + /// + /// Determines whether Material Design 3 is enabled for the application. + /// + /// The Android context (optional, reserved for future use). + /// + /// true if Material Design 3 is enabled (UseMaterial3=true); + /// false if Material Design 2 is active (default). + /// + /// + /// + /// This method reads the Material Design version configuration from the runtime + /// feature switch set by the UseMaterial3 MSBuild property. The value is cached + /// after the first call for performance. + /// + /// + /// Material Design 2 (AppCompat) is the default to maintain backward compatibility. + /// Material Design 3 must be explicitly enabled via the UseMaterial3 property. + /// + /// + public static bool IsMaterial3Enabled(Context? context = null) + { + // Return cached value if available + if (_isMaterial3Enabled.HasValue) + return _isMaterial3Enabled.Value; + + // Read from RuntimeFeature (configured via MSBuild) + _isMaterial3Enabled = RuntimeFeature.IsMaterial3Enabled; + + return _isMaterial3Enabled.Value; + } + + /// + /// Gets the Material Design version number currently in use. + /// + /// The Android context (optional, reserved for future use). + /// 2 for Material Design 2 (default), or 3 for Material Design 3. + public static int GetMaterialDesignVersion(Context? context = null) + { + return IsMaterial3Enabled(context) ? 3 : 2; + } + + /// + /// Resets the cached Material Design version. + /// + /// + /// This method is intended for testing purposes only and should not be called + /// in production code. The Material Design version is determined at build time + /// and should not change during application runtime. + /// + internal static void ResetCache() + { + _isMaterial3Enabled = null; + } + } +} diff --git a/src/Core/src/Platform/Android/MauiMaterialContextThemeWrapper.cs b/src/Core/src/Platform/Android/MauiMaterialContextThemeWrapper.cs index f2ddde546370..42fe06c15fbe 100644 --- a/src/Core/src/Platform/Android/MauiMaterialContextThemeWrapper.cs +++ b/src/Core/src/Platform/Android/MauiMaterialContextThemeWrapper.cs @@ -5,7 +5,10 @@ namespace Microsoft.Maui.Platform; internal class MauiMaterialContextThemeWrapper : ContextThemeWrapper { - public MauiMaterialContextThemeWrapper(Context context) : this(context, Resource.Style.Maui_MainTheme_Base) + public MauiMaterialContextThemeWrapper(Context context) + : this(context, MaterialDesignHelper.IsMaterial3Enabled(context) + ? Resource.Style.Maui_Material3_Theme_Base + : Resource.Style.Maui_MainTheme_Base) { } diff --git a/src/Core/src/Platform/Android/Resources/values/colors-material3.xml b/src/Core/src/Platform/Android/Resources/values/colors-material3.xml new file mode 100644 index 000000000000..37a16d3f5db7 --- /dev/null +++ b/src/Core/src/Platform/Android/Resources/values/colors-material3.xml @@ -0,0 +1,178 @@ + + + + + + #6750A4 + #FFFFFF + #EADDFF + #21005D + + + #625B71 + #FFFFFF + #E8DEF8 + #1D192B + + + #7D5260 + #FFFFFF + #FFD8E4 + #31111D + + + #BA1A1A + #FFDAD6 + #FFFFFF + #410002 + + + #FFFBFE + #1C1B1F + + + #FFFBFE + #1C1B1F + #E7E0EC + #49454F + + + #F3EDF7 + #ECE6F0 + #E6E0E9 + #F7F2FA + #FFFFFF + #FFFBFE + #DDD8E1 + + + #79747E + #CAC4D0 + + + #313033 + #F4EFF4 + #D0BCFF + + + #6750A4 + #000000 + + + #000000 + + + #1A6750A4 + #1F6750A4 + #296750A4 + + #141C1B1F + #1F1C1B1F + #291C1B1F + + + #EADDFF + #21005D + #D0BCFF + #4F378B + + #E8DEF8 + #1D192B + #CCC2DC + #4A4458 + + #FFD8E4 + #31111D + #EFB8C8 + #633B48 + + + + + #D0BCFF + #371E73 + #4F378B + #EADDFF + + + #CCC2DC + #332D41 + #4A4458 + #E8DEF8 + + + #EFB8C8 + #492532 + #633B48 + #FFD8E4 + + + #FFB4AB + #93000A + #690005 + #FFDAD6 + + + #10090D + #E6E1E5 + + + #10090D + #E6E1E5 + #49454F + #CAC4D0 + + + #211F26 + #2B2930 + #36343B + #1D1B20 + #0B0F14 + #3B383E + #141218 + + + #938F99 + #49454F + + + #E6E1E5 + #322F35 + #6750A4 + + + #D0BCFF + #000000 + + + #000000 + + + #1AD0BCFF + #1FD0BCFF + #29D0BCFF + + #14E6E1E5 + #1FE6E1E5 + #29E6E1E5 + + + #EADDFF + #21005D + #D0BCFF + #4F378B + + #E8DEF8 + #1D192B + #CCC2DC + #4A4458 + + #FFD8E4 + #31111D + #EFB8C8 + #633B48 + + + @color/md_theme_light_surface + @color/md_theme_dark_surface + diff --git a/src/Core/src/Platform/Android/Resources/values/styles-material3.xml b/src/Core/src/Platform/Android/Resources/values/styles-material3.xml new file mode 100644 index 000000000000..703fc37ce374 --- /dev/null +++ b/src/Core/src/Platform/Android/Resources/values/styles-material3.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Core/src/RuntimeFeature.cs b/src/Core/src/RuntimeFeature.cs index 4880b94bc743..0bce1aefc61d 100644 --- a/src/Core/src/RuntimeFeature.cs +++ b/src/Core/src/RuntimeFeature.cs @@ -27,6 +27,7 @@ static class RuntimeFeature const bool EnableDiagnosticsByDefault = false; const bool IsMeterSupportedByDefault = true; const bool EnableAspireByDefault = true; + const bool IsMaterial3EnabledByDefault = false; #pragma warning disable IL4000 // Return value does not match FeatureGuardAttribute 'System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute'. #if NET9_0_OR_GREATER @@ -147,6 +148,14 @@ internal set ? isEnabled : EnableAspireByDefault; +#if NET10_0_OR_GREATER + [FeatureSwitchDefinition($"{FeatureSwitchPrefix}.{nameof(IsMaterial3Enabled)}")] +#endif + public static bool IsMaterial3Enabled => + AppContext.TryGetSwitch($"{FeatureSwitchPrefix}.{nameof(IsMaterial3Enabled)}", out bool isEnabled) + ? isEnabled + : IsMaterial3EnabledByDefault; + #pragma warning restore IL4000 } } From 2f0faddf2e1092b0512119abd00cdfa402c0af74 Mon Sep 17 00:00:00 2001 From: NirmalKumarYuvaraj <97871636+NirmalKumarYuvaraj@users.noreply.github.com> Date: Tue, 9 Dec 2025 21:24:45 +0530 Subject: [PATCH 2/6] minor changes --- .../Microsoft.Maui.Controls.Common.targets | 41 ------------------- 1 file changed, 41 deletions(-) diff --git a/src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.Common.targets b/src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.Common.targets index 8b2318ed2b56..6c25c0708430 100644 --- a/src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.Common.targets +++ b/src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.Common.targets @@ -12,28 +12,6 @@ - - - false - - - - - - <_MauiAndroidMaterial3Enabled Condition="'$(UseMaterial3)' == 'true'">true - <_MauiAndroidMaterial3Enabled Condition="'$(UseMaterial3)' != 'true'">false - - - <_MauiMaterialDesignVersion Condition="'$(UseMaterial3)' == 'true'">3 - <_MauiMaterialDesignVersion Condition="'$(UseMaterial3)' != 'true'">2 - - false @@ -55,23 +33,4 @@ - - - - - <_MauiMaterialMessage Condition="'$(UseMaterial3)' == 'true'">Material Design 3 enabled (UseMaterial3=true) - <_MauiMaterialMessage Condition="'$(UseMaterial3)' != 'true'">Material Design 2 (default) - Set UseMaterial3=true to enable Material Design 3 - - - - - - From 7e0e6631ef31f47e19e5c9e6d3b4c90fe5248c6c Mon Sep 17 00:00:00 2001 From: NirmalKumarYuvaraj <97871636+NirmalKumarYuvaraj@users.noreply.github.com> Date: Tue, 9 Dec 2025 21:25:28 +0530 Subject: [PATCH 3/6] more changes --- .../netstandard2.0/Microsoft.Maui.Controls.Common.targets | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.Common.targets b/src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.Common.targets index 6c25c0708430..55462cab2279 100644 --- a/src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.Common.targets +++ b/src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.Common.targets @@ -11,7 +11,6 @@ '$([MSBuild]::GetTargetPlatformIdentifier($(TargetFramework)))' == 'tizen')">True - false @@ -32,5 +31,4 @@ - From b5d2aed52ec4fbdc9c9a04bac5ad091db2f16045 Mon Sep 17 00:00:00 2001 From: NirmalKumarYuvaraj <97871636+NirmalKumarYuvaraj@users.noreply.github.com> Date: Wed, 10 Dec 2025 14:17:33 +0530 Subject: [PATCH 4/6] Removed designhelper --- .../Platform/Android/MaterialDesignHelper.cs | 71 ------------------- .../MauiMaterialContextThemeWrapper.cs | 2 +- 2 files changed, 1 insertion(+), 72 deletions(-) delete mode 100644 src/Core/src/Platform/Android/MaterialDesignHelper.cs diff --git a/src/Core/src/Platform/Android/MaterialDesignHelper.cs b/src/Core/src/Platform/Android/MaterialDesignHelper.cs deleted file mode 100644 index e77e68dc1024..000000000000 --- a/src/Core/src/Platform/Android/MaterialDesignHelper.cs +++ /dev/null @@ -1,71 +0,0 @@ -using Android.Content; - -namespace Microsoft.Maui.Platform -{ - /// - /// Helper class for Material Design version detection and configuration on Android. - /// - /// - /// This helper provides runtime detection of whether Material Design 3 is enabled - /// through the UseMaterial3 MSBuild property. The configuration is cached after the - /// first access for performance. - /// - internal static class MaterialDesignHelper - { - private static bool? _isMaterial3Enabled; - - /// - /// Determines whether Material Design 3 is enabled for the application. - /// - /// The Android context (optional, reserved for future use). - /// - /// true if Material Design 3 is enabled (UseMaterial3=true); - /// false if Material Design 2 is active (default). - /// - /// - /// - /// This method reads the Material Design version configuration from the runtime - /// feature switch set by the UseMaterial3 MSBuild property. The value is cached - /// after the first call for performance. - /// - /// - /// Material Design 2 (AppCompat) is the default to maintain backward compatibility. - /// Material Design 3 must be explicitly enabled via the UseMaterial3 property. - /// - /// - public static bool IsMaterial3Enabled(Context? context = null) - { - // Return cached value if available - if (_isMaterial3Enabled.HasValue) - return _isMaterial3Enabled.Value; - - // Read from RuntimeFeature (configured via MSBuild) - _isMaterial3Enabled = RuntimeFeature.IsMaterial3Enabled; - - return _isMaterial3Enabled.Value; - } - - /// - /// Gets the Material Design version number currently in use. - /// - /// The Android context (optional, reserved for future use). - /// 2 for Material Design 2 (default), or 3 for Material Design 3. - public static int GetMaterialDesignVersion(Context? context = null) - { - return IsMaterial3Enabled(context) ? 3 : 2; - } - - /// - /// Resets the cached Material Design version. - /// - /// - /// This method is intended for testing purposes only and should not be called - /// in production code. The Material Design version is determined at build time - /// and should not change during application runtime. - /// - internal static void ResetCache() - { - _isMaterial3Enabled = null; - } - } -} diff --git a/src/Core/src/Platform/Android/MauiMaterialContextThemeWrapper.cs b/src/Core/src/Platform/Android/MauiMaterialContextThemeWrapper.cs index 42fe06c15fbe..66d0572426c7 100644 --- a/src/Core/src/Platform/Android/MauiMaterialContextThemeWrapper.cs +++ b/src/Core/src/Platform/Android/MauiMaterialContextThemeWrapper.cs @@ -6,7 +6,7 @@ namespace Microsoft.Maui.Platform; internal class MauiMaterialContextThemeWrapper : ContextThemeWrapper { public MauiMaterialContextThemeWrapper(Context context) - : this(context, MaterialDesignHelper.IsMaterial3Enabled(context) + : this(context, RuntimeFeature.IsMaterial3Enabled ? Resource.Style.Maui_Material3_Theme_Base : Resource.Style.Maui_MainTheme_Base) { From ba3d6534888a8bea2632c7a9ea083e94b0fea32d Mon Sep 17 00:00:00 2001 From: NirmalKumarYuvaraj <97871636+NirmalKumarYuvaraj@users.noreply.github.com> Date: Tue, 23 Dec 2025 15:57:35 +0530 Subject: [PATCH 5/6] Updated app level theming --- .../Platform/Android/MauiAppCompatActivity.cs | 4 +- .../MauiMaterialContextThemeWrapper.cs | 1 + .../Resources/values/colors-material3.xml | 178 ------------------ .../Resources/values/styles-material3.xml | 15 +- 4 files changed, 5 insertions(+), 193 deletions(-) delete mode 100644 src/Core/src/Platform/Android/Resources/values/colors-material3.xml diff --git a/src/Core/src/Platform/Android/MauiAppCompatActivity.cs b/src/Core/src/Platform/Android/MauiAppCompatActivity.cs index beac14cbc615..aa9b9a210e98 100644 --- a/src/Core/src/Platform/Android/MauiAppCompatActivity.cs +++ b/src/Core/src/Platform/Android/MauiAppCompatActivity.cs @@ -23,7 +23,9 @@ protected override void OnCreate(Bundle? savedInstanceState) savedInstanceState, AllowFragmentRestore, Resource.Attribute.maui_splash, - Resource.Style.Maui_MainTheme_NoActionBar); + RuntimeFeature.IsMaterial3Enabled + ? Resource.Style.Maui_Material3_Theme_NoActionBar + : Resource.Style.Maui_MainTheme_NoActionBar); base.OnCreate(savedInstanceState); WindowCompat.SetDecorFitsSystemWindows(Window, false); diff --git a/src/Core/src/Platform/Android/MauiMaterialContextThemeWrapper.cs b/src/Core/src/Platform/Android/MauiMaterialContextThemeWrapper.cs index 66d0572426c7..a1397a24cdea 100644 --- a/src/Core/src/Platform/Android/MauiMaterialContextThemeWrapper.cs +++ b/src/Core/src/Platform/Android/MauiMaterialContextThemeWrapper.cs @@ -5,6 +5,7 @@ namespace Microsoft.Maui.Platform; internal class MauiMaterialContextThemeWrapper : ContextThemeWrapper { + // MaterIsMaterial3Enabledial3 Flag needed for Control Level theming. App Level theming is handled in MauiAppCompatActivity public MauiMaterialContextThemeWrapper(Context context) : this(context, RuntimeFeature.IsMaterial3Enabled ? Resource.Style.Maui_Material3_Theme_Base diff --git a/src/Core/src/Platform/Android/Resources/values/colors-material3.xml b/src/Core/src/Platform/Android/Resources/values/colors-material3.xml deleted file mode 100644 index 37a16d3f5db7..000000000000 --- a/src/Core/src/Platform/Android/Resources/values/colors-material3.xml +++ /dev/null @@ -1,178 +0,0 @@ - - - - - - #6750A4 - #FFFFFF - #EADDFF - #21005D - - - #625B71 - #FFFFFF - #E8DEF8 - #1D192B - - - #7D5260 - #FFFFFF - #FFD8E4 - #31111D - - - #BA1A1A - #FFDAD6 - #FFFFFF - #410002 - - - #FFFBFE - #1C1B1F - - - #FFFBFE - #1C1B1F - #E7E0EC - #49454F - - - #F3EDF7 - #ECE6F0 - #E6E0E9 - #F7F2FA - #FFFFFF - #FFFBFE - #DDD8E1 - - - #79747E - #CAC4D0 - - - #313033 - #F4EFF4 - #D0BCFF - - - #6750A4 - #000000 - - - #000000 - - - #1A6750A4 - #1F6750A4 - #296750A4 - - #141C1B1F - #1F1C1B1F - #291C1B1F - - - #EADDFF - #21005D - #D0BCFF - #4F378B - - #E8DEF8 - #1D192B - #CCC2DC - #4A4458 - - #FFD8E4 - #31111D - #EFB8C8 - #633B48 - - - - - #D0BCFF - #371E73 - #4F378B - #EADDFF - - - #CCC2DC - #332D41 - #4A4458 - #E8DEF8 - - - #EFB8C8 - #492532 - #633B48 - #FFD8E4 - - - #FFB4AB - #93000A - #690005 - #FFDAD6 - - - #10090D - #E6E1E5 - - - #10090D - #E6E1E5 - #49454F - #CAC4D0 - - - #211F26 - #2B2930 - #36343B - #1D1B20 - #0B0F14 - #3B383E - #141218 - - - #938F99 - #49454F - - - #E6E1E5 - #322F35 - #6750A4 - - - #D0BCFF - #000000 - - - #000000 - - - #1AD0BCFF - #1FD0BCFF - #29D0BCFF - - #14E6E1E5 - #1FE6E1E5 - #29E6E1E5 - - - #EADDFF - #21005D - #D0BCFF - #4F378B - - #E8DEF8 - #1D192B - #CCC2DC - #4A4458 - - #FFD8E4 - #31111D - #EFB8C8 - #633B48 - - - @color/md_theme_light_surface - @color/md_theme_dark_surface - diff --git a/src/Core/src/Platform/Android/Resources/values/styles-material3.xml b/src/Core/src/Platform/Android/Resources/values/styles-material3.xml index 703fc37ce374..454bfe1ecd4e 100644 --- a/src/Core/src/Platform/Android/Resources/values/styles-material3.xml +++ b/src/Core/src/Platform/Android/Resources/values/styles-material3.xml @@ -2,7 +2,7 @@ @@ -22,17 +22,4 @@ ?attr/colorSurface ?attr/actionBarSize - - - - \ No newline at end of file From d6e41f071e9ca15d985dead6f6ffe5aaaccb0072 Mon Sep 17 00:00:00 2001 From: NirmalKumarYuvaraj <97871636+NirmalKumarYuvaraj@users.noreply.github.com> Date: Tue, 23 Dec 2025 15:59:24 +0530 Subject: [PATCH 6/6] minor refactoring --- .../src/Platform/Android/MauiMaterialContextThemeWrapper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core/src/Platform/Android/MauiMaterialContextThemeWrapper.cs b/src/Core/src/Platform/Android/MauiMaterialContextThemeWrapper.cs index a1397a24cdea..193de93257a0 100644 --- a/src/Core/src/Platform/Android/MauiMaterialContextThemeWrapper.cs +++ b/src/Core/src/Platform/Android/MauiMaterialContextThemeWrapper.cs @@ -5,7 +5,7 @@ namespace Microsoft.Maui.Platform; internal class MauiMaterialContextThemeWrapper : ContextThemeWrapper { - // MaterIsMaterial3Enabledial3 Flag needed for Control Level theming. App Level theming is handled in MauiAppCompatActivity + // IsMaterial3Enabled Flag needed for Control Level theming. App Level theming is handled in MauiAppCompatActivity public MauiMaterialContextThemeWrapper(Context context) : this(context, RuntimeFeature.IsMaterial3Enabled ? Resource.Style.Maui_Material3_Theme_Base