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.

Road to Xamarin Ninja: Xamarin.Forms or Xamarin.Native?

I have been thinking about this particular question a lot recently and I believe it is a great starter to this article series. This article is aimed at beginner developers and I’ll only discuss the key differences of both options.

So which one?

My major concern was simplicity – I am an impatient person and like to see some results ASAP – and also the UI-dependent aspects of native development, that I forgo with Forms. So how did I settle on one or another?

Beforehand, I should let you in on more context. I know the Swift programming language and the iOS environment, so my go to choice was native Xamarin.iOS. After consulting this with fellow developers and learning that Forms are all the more used in big companies, I decided to give them a go.

Furthemore, here you can check out a table to help you with the decision.

Xamarin.Forms prosXamarin.Native pros
One UI codebase for all platformsMaximum customization of UI
Custom UI renderers enabling custom controlsReuse of existing UI code (Interface Builder or AXML)
No need to know all the ins and outs of each platformWorks with all platform-specific APIs

In the next article we’ll look at the first bump on the road of taking up Xamarin.Forms.

Be sure to comment your opinion on this down below!

Image source: https://www.xamstatic.com/dist/images/pages/forms/crm-app@2x-gS9Gn7Ma.png