Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin Android SetBackgroundDrawable deprecated but not SetBackground()

var textView = parentView.FindViewById<TextView>(Resource.Id.txt_chat_message);
GradientDrawable gd = new GradientDrawable();
gd.SetCornerRadius(10);
gd.SetColor(Color.Yellow);
textView.SetBackgroundDrawable(gd);

As in the example above SetBackgroundDrawable allows me to control the color and radius programmatically. I have looked at SetBackgroundResouce but I cannot find a clear example as it just seems to take an ID to a resource that I could not change progamatically.

Could someone help me providing an alternative that gives me the flexibility to do the exact same as SetBackgroundDrawable above please?

like image 625
Matthew Barnden Avatar asked Nov 10 '15 17:11

Matthew Barnden


1 Answers

Use the Background property. Generally whenever Android has a getX/setX method with no arguments, Xamarin converts it to a C# style property named X.

var textView = parentView.FindViewById<TextView>(Resource.Id.txt_chat_message);
GradientDrawable gd = new GradientDrawable();
gd.SetCornerRadius(10);
gd.SetColor(Color.Yellow);
textView.Background = gd;
like image 141
Jason Avatar answered Sep 20 '22 17:09

Jason