Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin Forms - Set default TextColor

Is there any way to set the default text color to a specific color for all the page elements that contain text?

It doesn't make sense to me that I need to set a 'TextColor' attribute for every element that contain text.

Thanks!

like image 744
MrSonic Avatar asked Mar 05 '19 14:03

MrSonic


2 Answers

You can set the style of the elements containing text in the App.xaml. This will set the TextColor for all Labels, Buttons,... you use in your app:

    <Style TargetType="Label">
        <Setter Property="TextColor" Value="Red" />
    </Style>

    <Style TargetType="Button">
        <Setter Property="TextColor" Value="Red" />
    </Style>

    <Style TargetType="Entry">
        <Setter Property="TextColor" Value="Red" />
    </Style>

    <Style TargetType="Editor">
        <Setter Property="TextColor" Value="Red" />
    </Style>
...

Unfortunately you will have to add a new Style tag for all Visual Elements containing text. I've been searching for a cleaner way to define styles for all elements with text a while ago. But this seems to be the cleanest way to do it...

Hopefully Xamarin.Forms will add a more generic way to handle the styling.

like image 182
DenseCrab Avatar answered Nov 13 '22 22:11

DenseCrab


You can use Styles as shown above by DenseCrab. And you could also create a different class that derives from the Label class. And you can set some default properties like color in there.

like image 1
Saamer Avatar answered Nov 14 '22 00:11

Saamer