var textView = parentView.FindViewById<TextView>(Resource.Id.txt_chat_message);
GradientDrawable gd = new GradientDrawable();
gd.SetCornerRadius(10);
gd.SetColor(Color.Yellow);
textView.SetBackgroundDrawable(gd);
如上面的例子所示,
SetBackgroundDrawable
允许我以编程方式控制颜色和半径。我已经查看了SetBackgroundResouce
但是我找不到一个清晰的示例,因为它似乎只是将id带到一个我无法进行前瞻性更改的资源。有人能帮我提供一个替代方案,让我灵活地做与上述
SetBackgroundDrawable
完全相同的事情吗? 最佳答案
使用Background属性。一般来说,每当android有一个getx/setx方法没有参数时,xamarin就会将其转换为一个名为x的c样式属性。
var textView = parentView.FindViewById<TextView>(Resource.Id.txt_chat_message);
GradientDrawable gd = new GradientDrawable();
gd.SetCornerRadius(10);
gd.SetColor(Color.Yellow);
textView.Background = gd;