KubenQPL KubenQPL - 6 months ago 82
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

Have you tried SetBackgroundColor()?

btn.SetBackgroundColor(Android.Graphics.Color.Yellow);
Comments