Skip to content
Open
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue31889.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Maui.Controls.Sample"
x:Class="Maui.Controls.Sample.Issues.Issue31889">
<VerticalStackLayout Spacing="20"
HorizontalOptions="Center">
<HorizontalStackLayout>
<Label Text="Entry: "
VerticalOptions="Center"
TextColor="{AppThemeBinding Light=Black, Dark=White}"/>
<local:UITestEntry AutomationId="TestEntry"
IsCursorVisible="False"
IsSpellCheckEnabled="False"
Placeholder="Entry Placeholder"
PlaceholderColor="{AppThemeBinding Light=Green, Dark=Orange}"
Text="Entry Text"
TextColor="{AppThemeBinding Light=Blue, Dark=Red}"
WidthRequest="200"/>
</HorizontalStackLayout>
<HorizontalStackLayout>
<Label Text="Editor: "
TextColor="{AppThemeBinding Light=Black, Dark=White}"
VerticalOptions="Center"/>
<local:UITestEditor AutomationId="TestEditor"
IsCursorVisible="False"
IsSpellCheckEnabled="False"
Placeholder="Editor Placeholder"
PlaceholderColor="{AppThemeBinding Light=Green, Dark=Orange}"
Text="Editor Text"
TextColor="{AppThemeBinding Light=Blue, Dark=Red}"
WidthRequest="200"/>
</HorizontalStackLayout>
<HorizontalStackLayout Spacing="10"
HorizontalOptions="Center">
<Button AutomationId="LightThemeButton"
Text="Light Theme"
Clicked="OnLightThemeButtonClicked"
HorizontalOptions="Center"/>
<Button AutomationId="DarkThemeButton"
Text="Dark Theme"
Clicked="OnDarkThemeButtonClicked"
HorizontalOptions="Center"/>
</HorizontalStackLayout>
</VerticalStackLayout>
</ContentPage>
26 changes: 26 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue31889.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 31889, "Entry and Editor AppThemeBinding colors for text and placeholder reset to default on theme change", PlatformAffected.Android)]
public partial class Issue31889 : ContentPage
{
public Issue31889()
{
InitializeComponent();
this.SetAppThemeColor(BackgroundColorProperty, Colors.White, Colors.Black);
}
public void OnLightThemeButtonClicked(object sender, EventArgs e)
{
if (Application.Current is not null)
{
Application.Current.UserAppTheme = AppTheme.Light;
}
}

public void OnDarkThemeButtonClicked(object sender, EventArgs e)
{
if (Application.Current is not null)
{
Application.Current.UserAppTheme = AppTheme.Dark;
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue31889 : _IssuesUITest
{
public Issue31889(TestDevice testDevice) : base(testDevice) { }

private const string TestEntryId = "TestEntry";
private const string TestEditorId = "TestEditor";
private const string DarkThemeButtonId = "DarkThemeButton";
private const string LightThemeButtonId = "LightThemeButton";
private const string DoneButtonId = "Done";
private const string TextColorDarkTheme = "EntryAndEditorTextColorAppThemeBindingUpdatesOnDarkTheme";
private const string TextColorLightTheme = "EntryAndEditorTextColorAppThemeBindingUpdatesOnLightTheme";
private const string PlaceholderColorDarkTheme = "EntryAndEditorPlaceholderTextColorAppThemeBindingUpdatesOnDarkTheme";
private const string PlaceholderColorLightTheme = "EntryAndEditorPlaceholderTextColorAppThemeBindingUpdatesOnLightTheme";
public override string Issue => "Entry and Editor AppThemeBinding colors for text and placeholder reset to default on theme change";

[Test, Order(1)]
[Category(UITestCategories.Entry)]
public void EntryAndEditorTextColorAppThemeBindingUpdatesOnThemeChange()
{
App.WaitForElement(TestEntryId);
App.WaitForElement(DarkThemeButtonId);
App.Tap(DarkThemeButtonId);
VerifyScreenshot(TextColorDarkTheme);
App.WaitForElement(LightThemeButtonId);
App.Tap(LightThemeButtonId);
VerifyScreenshot(TextColorLightTheme);
}

[Test, Order(2)]
[Category(UITestCategories.Entry)]
public void EntryAndEditorPlaceholderTextColorAppThemeBindingUpdatesOnThemeChange()
{
App.WaitForElement(TestEntryId);
App.ClearText(TestEntryId);

App.WaitForElement(TestEditorId);
App.ClearText(TestEditorId);
#if MACCATALYST // On macOS, clearing the text in the Editor does not remove the full content.
App.ClearText(TestEditorId);
#endif
#if IOS
if (App.IsKeyboardShown())
{
App.WaitForElement(DoneButtonId);
App.Tap(DoneButtonId);
}
#endif
App.WaitForElement(DarkThemeButtonId);
App.Tap(DarkThemeButtonId);
VerifyScreenshot(PlaceholderColorDarkTheme);
App.WaitForElement(LightThemeButtonId);
App.Tap(LightThemeButtonId);
VerifyScreenshot(PlaceholderColorLightTheme);
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/Core/src/Platform/Android/EditTextExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static void UpdateTextColor(this EditText editText, Graphics.Color textCo
{
if (textColor is not null && PlatformInterop.CreateEditTextColorStateList(editText.TextColors, textColor.ToPlatform()) is ColorStateList c)
editText.SetTextColor(c);
else
else if (textColor is null)
Copy link
Contributor

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;

Copy link
Contributor Author

@TamilarasanSF4853 TamilarasanSF4853 Oct 10, 2025

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.

{
// Fallback to system default color
if (OperatingSystem.IsAndroidVersionAtLeast(23) && editText.Context?.Theme is Resources.Theme theme)
Expand Down Expand Up @@ -151,7 +151,7 @@ public static void UpdatePlaceholderColor(this EditText editText, Graphics.Color
{
if (placeholderTextColor is not null && PlatformInterop.CreateEditTextColorStateList(editText.HintTextColors, placeholderTextColor.ToPlatform()) is ColorStateList c)
editText.SetHintTextColor(c);
else
else if (placeholderTextColor is null)
{
// Fallback to system default color
var typedValue = new TypedValue();
Expand Down