How do i programatically set the background color of a view using xamarin from the hex value
For example
view.BackgroundColor = Color.FromHex("#00162E");
How do i programatically set the background color of a view using xamarin from the hex value
For example
view.BackgroundColor = Color.FromHex("#00162E");
I believe you're looking for the ParseColor method that takes in a string and returns the integer color.
view.BackgroundColor = Android.Graphics.Color.ParseColor("#FF6A00");
Supported formats are:
From their example.. I think you just need to drop the #.
view.BackgroundColor = Color.FromHex("FF6A00")
http://developer.xamarin.com/guides/cross-platform/xamarin-forms/working-with/colors/
Depending on your target, you may want to try the parseColor method on the color class instead.
How to get a Color from hexadecimal Color String
public static int parseColor (String colorString)
It claims to take hex values :
... formats are: #RRGGBB #AARRGGBB 'red', 'blue', 'green', 'black', 'white', 'gray', 'cyan', 'magenta', 'yellow', 'lightgray', 'darkgray'
To change the color programatically of some text in the .xaml file you can do this, in for instance a switch loop:
FindViewById<TextView>(Resource.Id.->insert the id/name from the .xaml file <-).SetBackgroundColor(Color.Red);
break;
I hope it helps
Worked for me this:
BackgroundColor = Color.FromHex("#fcf2e4");
My Xamarin.Forms Version: 5.0.0.2012.
I found Code Here