So I have the main background color set, and I want to toggle the color by clicking a button. I can get the color to change on first click, but it won't return to the original color on second click:
See code:
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
// Set your view layout layout resource file
SetContentView (Resource.Layout.Main);
// Initilize button from the layout resource
Button button = FindViewById<Button> (Resource.Id.myButton);
button.Click += delegate {
//display toast message
if (BackgroundIsNormal()) {
SetNewBackgroundColor();
} else {
BackgroundIsNormal();
}
};
}
private bool BackgroundIsNormal()
{
LinearLayout mainLayout = FindViewById<LinearLayout> (Resource.Id.linearlayout2);
mainLayout.SetBackgroundColor (Color.Aqua);
return true;
}
private bool SetNewBackgroundColor()
{
LinearLayout mainLayout = FindViewById<LinearLayout> (Resource.Id.linearlayout2);
mainLayout.SetBackgroundColor (Color.Green);
return true;
}