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 @@ -351,6 +351,10 @@
Condition="'$(_EnableMauiAspire)' != ''"
Value="$(_EnableMauiAspire)"
Trim="true" />
<RuntimeHostConfigurationOption Include="Microsoft.Maui.RuntimeFeature.IsMaterial3Enabled"
Condition="'$(UseMaterial3)' != ''"
Value="$(UseMaterial3)"
Trim="true" />
</ItemGroup>
</Target>

Expand Down
4 changes: 3 additions & 1 deletion src/Core/src/Platform/Android/MauiAppCompatActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ namespace Microsoft.Maui.Platform;

internal class MauiMaterialContextThemeWrapper : ContextThemeWrapper
{
public MauiMaterialContextThemeWrapper(Context context) : this(context, Resource.Style.Maui_MainTheme_Base)
// 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
: Resource.Style.Maui_MainTheme_Base)
{
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<!-- Material 3 Base Theme (Automatically switches between light/dark) -->
<style name="Maui.Material3.Theme.Base" parent="Theme.Material3.DayNight">
<!-- For .NET 9 we opt out of edge to edge enforcement by default -->
<item name="maui_edgetoedge_optout">true</item>
<item name="maui_splash">false</item>
</style>


<!-- Material 3 No Action Bar Theme -->
<style name="Maui.Material3.Theme.NoActionBar" parent="Maui.Material3.Theme.Base">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="windowActionModeOverlay">true</item>
<item name="android:actionModeBackground">?attr/colorSurface</item>
<item name="android:actionModeStyle">@style/Material3ActionMode</item>
</style>

<!-- Material 3 Action Mode -->
<style name="Material3ActionMode">
<item name="android:background">?attr/colorSurface</item>
<item name="android:height">?attr/actionBarSize</item>
</style>
</resources>
9 changes: 9 additions & 0 deletions src/Core/src/RuntimeFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
Loading