title: Android - Change background color of margin
body: <p>I have a fragment named <code>HostFragment</code> which nests one to four other fragments. </p>
  
  <p>This is the layout of <code>HostFragment</code>:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/hostFragmentLayout"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_marginTop="12dp"&gt;
  
      &lt;TableRow
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_weight="1"&gt;
  
          &lt;RelativeLayout
              android:id="@+id/fragmentContainer1"
              android:layout_width="wrap_content"
              android:layout_height="match_parent"
              android:layout_weight="1"/&gt;
  
          &lt;RelativeLayout
              android:id="@+id/fragmentContainer2"
              android:layout_width="wrap_content"
              android:layout_height="match_parent"
              android:layout_weight="1"/&gt;
  
      &lt;/TableRow&gt;
  
      &lt;TableRow
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_weight="1"&gt;
  
          &lt;RelativeLayout
              android:id="@+id/fragmentContainer3"
              android:layout_width="wrap_content"
              android:layout_height="match_parent"
              android:layout_weight="1"/&gt;
  
          &lt;RelativeLayout
              android:id="@+id/fragmentContainer4"
              android:layout_width="wrap_content"
              android:layout_height="match_parent"
              android:layout_weight="1"/&gt;
  
      &lt;/TableRow&gt;
  
  &lt;/TableLayout&gt;
  </code></pre>
  
  <p>The important part of this is <code>android:layout_marginTop="12dp"</code>. </p>
  
  <p><strong>Background:</strong> The nested fragments cover the entirety of <code>HostFragment</code> except for this margin. When the nested fragments change their background color (by calling <code>Canvas#drawColor</code>), <code>HostFragment</code> needs to also change the color of this margin to match. I store the needed color in <code>SharedPreferences</code>.</p>
  
  <p><strong>Behavior:</strong> If the user goes from <code>HostFragment</code> to <code>SettingsActivity</code>, changes the color, and comes back to <code>HostFragment</code>, the nested fragments will change their color immediately (through their <code>onResume()</code> methods), but <code>HostFragment</code>'s margin will still be the old color. If the user then leaves <code>HostFragment</code> and goes to another fragment, then returns to <code>HostFragment</code>, the margin will update its color. I don't know how or why - I have no code in <code>HostFragment</code> to update the color. The code in <code>HostFragment</code> only deals in swapping in and out nested fragments.</p>
  
  <p><strong>Problem:</strong> I need the margin color to update right away, so in <code>onResume()</code>, I've tried something like <code>mTableLayout.setBackgroundColor(...)</code> or even <code>mView.setBackgroundColor(...)</code> (<code>mView</code> is the layout I inflate in <code>onCreateView()</code>). This still doesn't work, and the color will only update if the user leaves and comes back. </p>
  
  <p><strong>Question:</strong> How can I change the color of the margin to match an <code>int</code> value in <code>SharedPreferences</code> once the user returns to <code>HostFragment</code> from another <code>Activity</code> (<em>i.e.</em> Right after the user returns from the Settings)?</p>
  
  <p>Thank you in advance!</p>