title: Android: Change Background Color of Fragment
body: <p>I tried changing the background color of a fragment, but a small problem occurred.</p>
  
  <pre><code>public class MainActivity extends FragmentActivity {
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
      }
  }
  </code></pre>
  
  <p>So, shown <b>above</b> is the code I had for my main class that calls the XML file for the fragment.</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="horizontal" &gt;
  
      &lt;fragment
          android:id="@+id/fragment1"
          android:name="com.northreal.practice.FirstFragment"
          android:layout_width="0dip"
          android:layout_height="match_parent"
          android:layout_weight="1"
          android:background="#CBA" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><b>Above</b> is the main.xml layout that is called by the main class (MainActivity).</p>
  
  <pre><code>public class FirstFragment extends Fragment {
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup parent,
              Bundle savedInstanceState) {
          return inflater.inflate(R.layout.main, parent, false);
      }
  }
  </code></pre>
  
  <p><b>Above</b> the XML file with the fragment calls this class.</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="horizontal"
       &gt;
  
      &lt;TextView
          android:id="@+id/tv"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="BLAHHHH"
          android:layout_gravity="center_vertical" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>This layout <b>above</b> is inflated by the class FirstFragment</p>
  
  <p>So, why doesn't this actually change the color of the background of my fragment?</p>