KubenQPL KubenQPL - 2 years ago 268
Android Question

How can i change background of programmatically added button in C# Xamarin?

I tried to make this, that way: btn.Background(Android.Graphics.Color holo_blue_dark); but it doesn't work, here is my code of adding this button (it's working fine except this background). Can you tell how to set other properties like height, margin etc.?

Button btn = new Button(this);
i++;
title = title.Trim(new Char[] { '"', '<', '>' });
btn.Text = title;
btn.Id = i;
layout.AddView(btn);

Answer Source

Have you tried SetBackgroundColor()?

btn.SetBackgroundColor(Android.Graphics.Color.Yellow);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download