Road to Xamarin Ninja: Color confusion in Xamarin.Forms

While reading up on Xamarin.Forms, I came across some interesting properties within the Color structure – the Color.Transparent , Color.Accent  and Color.Default.

Color.Transparent

In the Xamarin.Forms documentation this color has the RGBA values of (255, 255, 255, 0). To a user this color seems transparent, meaning they don’t see it at all. In it’s essence though, it is just a red color with the alpha channel set to 0.

Color.Accent

The accent color is a very interesting one, since on all platforms this one means something different.

First it is worth noting, that Android as well as Windows Phone and Window, allow for accent color change. This is not true with iOS, though.

For the purpose of this article, I used the Android Emulator and iOS Simulator in Visual Studio to find out the exact RGBA color represenations. With Android I got  R: 1, G:0.250980406999588, B: 0.505882382392883, A: 1 and with iOS  R: 0.196078434586525, G:0.309803932905197, B: 0.521568655967712, A: 1. As you can see, the colors, in this case, are platform-dependent.

Also, if a user were to change his phone’s UI to a dark theme, we would get different results.

Color.Default

Xamarin.Forms APIs use this color as a default for most views. It’s RGBA values are all set to -1, which in normal cases wouldn’t form any real color.

With views, like a Label, their BackgroundColor property is also set to  Color.Default. In this case, it is a transparent color. But while their TextColor property is also set to Color.Default, that one is actually dependent on the OS and the accent color.

Overall, this topic carries more that I could describe in a short article, but I hope you got the gist of it.

Leave a Reply

Your email address will not be published. Required fields are marked *