I want a button's text color to be the same on both iOS and Android. So I thought I'd just set the TextColor property in code to the color I wanted. On iOS, the disabled text color is still grey (which is what I want), however, on Android, the disabled text color is the same as the enabled text color. How do I make the disabled text color on Android grey (or whatever its default is for a disabled button)? Thanks
That is the default behavior in Xamarin.Forms. To work around that and achieve a custom color, you can:
Because triggers are the most straightforward and consistent way of achieving what you want, I'll only cover that. You can see the xamarin docs for more information about custom renderers.
Using triggers, you can dynamically change the font color to gray when it is not enabled. See the docs for more information about triggers.
<Button Text="I am a Button">
<Button.Triggers>
<Trigger TargetType="Button"
Property="IsEnabled" Value="true">
<Setter Property="TextColor" Value="Red" />
<!-- red is the desired color when the button is enabled.-->
</Trigger>
<Trigger TargetType="Button"
Property="IsEnabled" Value="false">
<Setter Property="TextColor" Value="Gray" />
<!-- gray is the desired color when the button is disabled.-->
</Trigger>
</Button.Triggers>
</Button>