Lazar Nikolov Lazar Nikolov - 6 months ago 45
C# Question

Custom renderer in Android doesn't allow changing background color of View

I've made a ViewCellRenderer where I have two labels and a vertical view that represents a line (full height, 2dp width). Now, setting up the text works fine, but when I try to change the background color of the View, the renderer displays it as transparent. Here's my code:

Android.Views.View colorStripe = v.FindViewById<Android.Views.View>(Resource.Id.llColorStripe);
Android.Graphics.Color stripeColor = new Android.Graphics.Color();
stripeColor = stripeColor.FromHexString(x.StripeColor);

x.StripeColor is the color hex that I want to apply dynamically for every cell. I've debugged it, the color gets built correctly and applied to the view, but when I continue the execution there's no color stripe on the UI. I've debugged the hierarchy view and I can see that the stripe has width and height, but no background color at all. But there are no problems for iOS:

enter image description here
enter image description here

Anyone knows how can I fix this? Thanks a lot!


I fixed it. Instead of creating a color variable and applying the color string to it, I used Xamarin's function ParseColor:

colorStripe.SetBackgroundColor (Android.Graphics.Color.ParseColor (x.StripeColor));