-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Android][Regression] Fixed Entry and Editor AppThemeBinding colors for text and placeholder reset to default on theme change #31891
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
/azp run MAUI-UITests-public |
Azure Pipelines successfully started running 1 pipeline(s). |
/backport to release/9.0.1xx-sr12 |
Started backporting to release/9.0.1xx-sr12: https://github.com/dotnet/maui/actions/runs/18353595854 |
There was a problem hiding this 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 fixes a regression in Android Entry and Editor controls where AppThemeBinding colors for text and placeholder would reset to default values when the application theme changes. The fix involves adding null checks to prevent the fallback color logic from executing when AppThemeBinding colors should be preserved.
Key changes:
- Modified the
else
conditions inUpdateTextColor
andUpdatePlaceholderColor
methods to only execute when the color parameter is explicitly null - Added comprehensive UI tests to verify the fix works correctly across theme changes
- Created test UI demonstrating the issue with AppThemeBinding colors
Reviewed Changes
Copilot reviewed 4 out of 16 changed files in this pull request and generated no comments.
File | Description |
---|---|
src/Core/src/Platform/Android/EditTextExtensions.cs |
Changed else to else if (color is null) in color update methods to prevent overriding AppThemeBinding colors |
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue31889.cs |
Added NUnit tests to verify text and placeholder colors update correctly on theme changes |
src/Controls/tests/TestCases.HostApp/Issues/Issue31889.xaml.cs |
Created test page code-behind with theme switching functionality |
src/Controls/tests/TestCases.HostApp/Issues/Issue31889.xaml |
Created test UI with Entry and Editor controls using AppThemeBinding colors |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
if (textColor is not null && PlatformInterop.CreateEditTextColorStateList(editText.TextColors, textColor.ToPlatform()) is ColorStateList c) | ||
editText.SetTextColor(c); | ||
else | ||
else if (textColor is null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can simplify the conditions just with an initial check:
if (editText is null)
return;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jsuarezruiz When the CreateEditTextColorStateList method is called a second time with the same color, it returns null. As a result, the else block is executed even when a TextColor is provided through the Entry or Editor controls, causing it to fall back to the default color. To prevent this, an else if condition was added to check whether the TextColor is set. Now, the else block executes only when the TextColor is null, ensuring that the provided text color is not overridden.
/backport to release/9.0.1xx-sr12 |
Started backporting to release/9.0.1xx-sr12: https://github.com/dotnet/maui/actions/runs/18411780331 |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
Issue Details
On Android, the Entry and Editor controls do not respect the AppThemeBinding colors for their placeholder and text when the application theme changes (e.g., from Light to Dark).
Root cause
The root cause of the issue is that the UpdateTextColor method is called twice. During the first call, the colors are set correctly. However, when the RequestedTheme changes, the method is called again, and the same color is used to create the ColorStateList, which returns null the second time. As a result, the else block executes and overrides the text color with the default value.
Description of Change
Fixed the Android Entry and Editor controls to properly respect AppThemeBinding colors when the theme changes. Added explicit handling for null text and placeholder colors to prevent AppThemeBinding colors from being overridden by default colors.
Regressed PR: #30603
Issue Fixed
Fixes #31889
Tested the behavior in the following platforms.
Output images
Android
Screen.Recording.2025-10-07.at.1.08.20.PM.mov
Screen.Recording.2025-10-07.at.12.59.22.PM.mov