Skip to content
Merged
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
19 changes: 13 additions & 6 deletions src/Core/src/Platform/Android/EditTextExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Android.Views.InputMethods;
using Android.Widget;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Maui.Graphics;
using static Android.Views.View;
using static Android.Widget.TextView;

Expand Down Expand Up @@ -47,13 +48,19 @@ public static void UpdateTextColor(this EditText editText, Graphics.Color textCo
else
{
// Fallback to system default color
var typedValue = new TypedValue();
if (OperatingSystem.IsAndroidVersionAtLeast(23) &&
editText.Context?.Theme is Resources.Theme theme &&
theme.ResolveAttribute(Android.Resource.Attribute.TextColorPrimary, typedValue, true) &&
editText.Resources?.GetColor(typedValue.ResourceId, theme) is Android.Graphics.Color color)
if (OperatingSystem.IsAndroidVersionAtLeast(23) && editText.Context?.Theme is Resources.Theme theme)
{
editText.SetTextColor(color);
using var ta = theme.ObtainStyledAttributes([Android.Resource.Attribute.TextColorPrimary]);
var cs = ta.GetColorStateList(0);

if (cs is not null)
{
int[] DisabledState = [-Android.Resource.Attribute.StateEnabled];
int[] EnabledState = [Android.Resource.Attribute.StateEnabled];
var state = editText.Enabled ? EnabledState : DisabledState;
var color = new Android.Graphics.Color(cs.GetColorForState(state, Colors.Black.ToPlatform()));
editText.SetTextColor(color);
}
}
}
}
Expand Down
Loading