title: Change Background of View in Xamarin Android
body: <p>In my app I want to change the background of the view to a color based on an integer value. Everything is working fine, except for when the value changes. After executing the method only a part of the view gets updated. After switching out of the application en switching back, the whole view is updated correctly, but how could I do this without switching? </p>
  
  <p>Code for performing background color changes: </p>
  
  <pre><code>public void SetColor(int status)
      {
          View colorView = FindViewById(Resource.Id.view1);
  
          // Find the root view
          View root = colorView.RootView;
          string color = "";
          Log.Debug(TAG, string.Format("SetColor: {0}", status));
  
          switch (status)
          {
              case 1:
                  Log.Debug(TAG, "1");
                  color = "Red";
                  break;
              case 2:
                  Log.Debug(TAG, "2");
                  color = "Yellow";
                  break;
              case 3:
                  Log.Debug(TAG, "3");
                  color = "Green";
                  break;
              case 4:
                  Log.Debug(TAG, "4");
  
                  color = "YellowGreen";
                  break;
              case 5:
                  Log.Debug(TAG, "5");        
                  color = "Grey";
                  break;
              default:
                  Log.Debug(TAG, "6");
                  break;
          }
          Log.Debug(TAG, string.Format("Color: {0}", color));
          root.SetBackgroundColor(Color.ParseColor(color));
      }
  </code></pre>
  
  <p><strong>Edit 1</strong></p>
  
  <p>The method is called from the Database class and is called when a value changes in the database:</p>
  
  <pre><code>void PostgresNotification(object sender, NpgsqlNotificationEventArgs e)
      {
          var fase = e.AdditionalInformation;
          main.SetColor(Convert.ToInt32(fase));
      }
  </code></pre>
  
  <p>Where main is passed in the Database constructor </p>
  
  <pre><code>MainActivity main;
  public Database(MainActivity mainActivity)
      {
              //Shortened for brevity
              main = mainActivity;
      }
  </code></pre>
  
  <p>Constructor is called in MainActivity's OnCreate()</p>
  
  <pre><code>protected override void OnCreate(Bundle savedInstanceState)
      {
          //Shortened for brevity
          db = new Database(this);
      }
  </code></pre>
  
  <p>Problem:</p>
  
  <p><a href="https://i.stack.imgur.com/c1vk3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/c1vk3.png" alt="Update problem"></a></p>