Skip to content

Conversation

@NirmalKumarYuvaraj
Copy link
Contributor

@NirmalKumarYuvaraj NirmalKumarYuvaraj commented Jul 3, 2025

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Root cause

The problem is that the MauiMaterialButton style has a parent of Widget.MaterialComponents.Button.UnelevatedButton, which requires the application theme to be based on Theme.MaterialComponents. However, the MauiMaterialButton constructor is wrapping the context with just the button style, not ensuring the proper theme hierarchy.

Description of change

  • This pull request addresses an issue where certain Material components on Android require a specific app theme (Theme.MaterialComponent) to avoid runtime exceptions. It introduces a new MauiMaterialContextThemeWrapper to ensure the correct theme is applied to Material components and adds test cases to validate the changes.

Fix for Material Component Theme Issue:

  • src/Core/src/Platform/Android/MauiMaterialContextThemeWrapper.cs: Added MauiMaterialContextThemeWrapper class to wrap the Android context with the appropriate Material theme (Resource.Style.Maui_MainTheme_Base). This ensures Material components use the correct theme.

  • src/Core/src/Handlers/CheckBox/CheckBoxHandler.Android.cs : Updated CheckBoxHandler to use MauiMaterialContextThemeWrapper.Create(Context) when creating MaterialCheckBox, ensuring the correct theme is applied.

  • src/Core/src/Platform/Android/MauiMaterialButton.cs : Modified MauiMaterialButton to use MauiMaterialContextThemeWrapper.Create(context) for all constructors, ensuring consistent theme application for Material buttons.

Reference

public MaterialButtonRenderer(Context context)
: this(MaterialContextThemeWrapper.Create(context), null) { }

https://github.com/dotnet/maui/blob/main/src/Compatibility/Material/src/Android/MaterialContextThemeWrapper.cs

Validated the behaviour in the following platforms

  • Android
  • Windows
  • iOS
  • Mac

Issues Fixed

Fixes #13356

Output

Before After
image
After.mov

@dotnet-policy-service dotnet-policy-service bot added community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration labels Jul 3, 2025
@NirmalKumarYuvaraj NirmalKumarYuvaraj marked this pull request as ready for review July 4, 2025 07:46
Copilot AI review requested due to automatic review settings July 4, 2025 07:46
@NirmalKumarYuvaraj NirmalKumarYuvaraj requested a review from a team as a code owner July 4, 2025 07:46
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 ensures that Android Material controls are themed correctly by introducing a context wrapper, updating handlers to use it, and adding repro tests.

  • Added a MauiMaterialContextThemeWrapper to wrap Android contexts with the Material theme.
  • Updated MauiMaterialButton and CheckBoxHandler.Android to use the new theme wrapper.
  • Added a HostApp sample page and corresponding UI tests to validate the fix for Issue #13356.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/Core/src/Platform/Android/MauiMaterialContextThemeWrapper.cs New wrapper class to apply the correct Material theme to Android views.
src/Core/src/Platform/Android/MauiMaterialButton.cs Updated button constructors to use MauiMaterialContextThemeWrapper.
src/Core/src/Handlers/CheckBox/CheckBoxHandler.Android.cs Updated MaterialCheckBox instantiation to use the theme wrapper.
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue13356.cs Added UITests for Material button and checkbox dialogs on Android.
src/Controls/tests/TestCases.HostApp/Issues/Issue13356.cs Added HostApp sample page and dialog implementation for Issue #13356.
Comments suppressed due to low confidence (1)

src/Controls/tests/TestCases.HostApp/Issues/Issue13356.cs:45

  • The dialog's Button is missing an AutomationId, so the test WaitForElement("Dialog Button") may not locate it. Consider setting an AutomationId on this Button (e.g., AutomationId = "DialogButton") to match the test or update the test to query by text explicitly.
			Content = new Button { Text = "Dialog Button", Padding = new Thickness(30) }


namespace Microsoft.Maui.Platform;

internal class MauiMaterialContextThemeWrapper : ContextThemeWrapper
Copy link
Contributor

Choose a reason for hiding this comment

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

Each call wraps the context in a new ContextThemeWrapper. This is lightweight but worth monitoring if frequently recreated during inflation.

@PureWeen PureWeen changed the base branch from main to inflight/current October 31, 2025 20:29
@PureWeen PureWeen merged commit fa25606 into dotnet:inflight/current Oct 31, 2025
2 checks passed
PureWeen pushed a commit that referenced this pull request Nov 11, 2025
* Fixed Exception

* Optimized code

* Updated fix

* fixed checkbox

* enabled android test

* Fixed typo
github-actions bot pushed a commit that referenced this pull request Nov 11, 2025
* Fixed Exception

* Optimized code

* Updated fix

* fixed checkbox

* enabled android test

* Fixed typo
github-actions bot pushed a commit that referenced this pull request Nov 14, 2025
* Fixed Exception

* Optimized code

* Updated fix

* fixed checkbox

* enabled android test

* Fixed typo
github-actions bot pushed a commit that referenced this pull request Nov 15, 2025
* Fixed Exception

* Optimized code

* Updated fix

* fixed checkbox

* enabled android test

* Fixed typo
github-actions bot pushed a commit that referenced this pull request Nov 15, 2025
* Fixed Exception

* Optimized code

* Updated fix

* fixed checkbox

* enabled android test

* Fixed typo
github-actions bot pushed a commit that referenced this pull request Nov 18, 2025
* Fixed Exception

* Optimized code

* Updated fix

* fixed checkbox

* enabled android test

* Fixed typo
github-actions bot pushed a commit that referenced this pull request Nov 18, 2025
* Fixed Exception

* Optimized code

* Updated fix

* fixed checkbox

* enabled android test

* Fixed typo
github-actions bot pushed a commit that referenced this pull request Nov 18, 2025
* Fixed Exception

* Optimized code

* Updated fix

* fixed checkbox

* enabled android test

* Fixed typo
github-actions bot pushed a commit that referenced this pull request Nov 20, 2025
* Fixed Exception

* Optimized code

* Updated fix

* fixed checkbox

* enabled android test

* Fixed typo
github-actions bot pushed a commit that referenced this pull request Nov 20, 2025
* Fixed Exception

* Optimized code

* Updated fix

* fixed checkbox

* enabled android test

* Fixed typo
@github-actions github-actions bot locked and limited conversation to collaborators Dec 1, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Java.Lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponent.

3 participants