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?
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With