Issue
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?
Solution
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;
Answered By - Jason
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.