I seem to have some troubles with the TextColor of my Entry on iOS when Dark Mode is enabled. Whenever I set the Entry's Enabled state to false, the TextColor turns white and it's not possible to change. I used the following simple code to reproduce this.
Page.xaml
<Entry x:Name="TestEntry" />
Page.xaml.cs
public OnboardingPage()
{
InitializeComponent();
TestEntry.Text = "Testo";
TestEntry.TextColor = Color.Blue;
TestEntry.IsEnabled = false;
}
I am currently using the latest version of Xamarin.Forms. (4.4.0.991640)
Does anybody have an idea what's going wrong here? I don't think this is expected behavior..
Thanks in advance!
Set the current user themeUserAppTheme = OSAppTheme. Dark; In this example, the application is set to use the theme defined for the system dark mode, regardless of which system theme is currently operational. Set the UserAppTheme property to OSAppTheme.
In the meanwhile I have found the fix necessary to my question.
Apparently the EntryRenderer on iOS uses uses the default color when legacy color management is enabled and the Entry is disabled. Setting the legacyColorManagement to False on the Entry solves this issue.
XF check for legacycolormanagement https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Platform.iOS/Extensions/VisualElementExtensions.cs#L15
XF check for TextColor of the Entry https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Platform.iOS/Renderers/EntryRenderer.cs#L272
I've added following code to my *Page.xaml and now the colors are rendering correctly:
*Page.xaml
<ContentPage xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core"
...>
<Entry ios:VisualElement.IsLegacyColorModeEnabled="False"
.../>
The reason that is happening because of how iOS works with the dark mode for you to handle this you have to add the following in your Info.Plist
<key>UIUserInterfaceStyle</key>
<string>Light</string>
What this will do is stop your app from changing anything when Dark mode is turned on i.e. it is sort of an opt-out
Goodluck
Feel free to get back if you have questions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With