title: Can I set android background colour based on a variable?
body: <p>This is my code:</p>
  
  <pre><code>private LinearLayout erBackground;
  erBackground = (LinearLayout) findViewById(R.id.erBackground);
  
  String background = "YELLOW"
  erBackground.setBackgroundColor(Color.background)
  </code></pre>
  
  <p>What would I need to do to background to allow it to change the background to yellow?</p>
  
  <p>The above is a simplified version of my code. What I am trying to do is pass an item from a spinner ("YELLOW") on one activity to Shared Preferences, and then onCreate of the next activity I want to check if a background is stored in Shared Preferences.. if it is then change the colour to this.</p>
  
  <p>OnClick code:</p>
  
  <pre><code>SharedPreferences pref = getApplicationContext().getSharedPreferences("MyPref", MODE_PRIVATE);
  SharedPreferences.Editor editor = pref.edit();
  
  editor.putString("background", personaliseBackgroundSpinner.getSelectedItem().toString().toUpperCase());
  editor.putString("font", personaliseFontSpinner.getSelectedItem().toString().toUpperCase());
  
  editor.commit();
  </code></pre>
  
  <p>OnCreate code of the next activity:</p>
  
  <pre><code>SharedPreferences pref = getApplicationContext().getSharedPreferences("MyPref", MODE_PRIVATE);
  SharedPreferences.Editor editor = pref.edit();
  
  
  String background = pref.getString("background", null); // background = "YELLOW"
  
  if (background != null) {
      erBackground.setBackgroundColor(Color.);
  }
  </code></pre>
  
  <p>The shared preferences part works though, my problem is that it doesn't let me use a variable after color and wants me to use a color name, but what if the color changes? Do I have to a big long if else statement for each color?</p>
  
  <p>Edit:
  XML layout for second activity:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:id="@+id/erBackground"&gt;
  
  &lt;TextView
      android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed neque lacus, tempus eget ultrices id, efficitur id metus. Suspendisse convallis quam vel orci congue lobortis. Praesent et venenatis tortor. Nam non venenatis erat, eget tempus metus."
      android:id="@+id/erUserResultsTextView"
      android:layout_below="@+id/erSubmitBtn"
      android:layout_centerHorizontal="true"
      android:layout_marginTop="41dp" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>