title: Android - How to set color of a TextView and background together with SharedPreferences
body: <p>in my app I have a menu button called "Settings" in which I can choose what colours set up to the background of some layout. Unfortunately I combine two layouts together to show what I want to show, and the problem is that I can only set background colour (that is in a layout) but not the the colour of TextView (that is in the other layout). </p>
  
  <p>Layout main.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent" 
  android:id="@+id/main_layout"&gt;
  &lt;EditText 
  android:id="@+id/editText1" 
  android:layout_height="65dip" 
  android:layout_marginTop="2dip"
  android:hint="Scrivi" 
  android:layout_width="fill_parent" /&gt;
  &lt;ListView android:id="@+id/list" 
  android:layout_height="wrap_content" 
  android:layout_width="match_parent" 
  android:fastScrollEnabled="true"&gt;
  &lt;/ListView&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Layout listitem_row.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:id="@+id/main_layout"&gt;
  &lt;TextView
  android:id="@+id/textView1"
  android:text="TextView"
  android:layout_height="wrap_content"
  android:textAppearance="?android:attr/textAppearanceLarge" 
  android:layout_width="fill_parent"&gt;
  &lt;/TextView&gt;
  &lt;TextView
  android:text="TextView"
  android:id="@+id/textView2"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"&gt;
  &lt;/TextView&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>MainActivity:</p>
  
  <pre><code>import java.util.ArrayList;
  
  import android.app.Activity;
  import android.content.Intent;
  import android.content.SharedPreferences;
  import android.content.SharedPreferences.Editor;
  import android.graphics.Color;
  import android.os.Bundle;
  import android.preference.PreferenceManager;
  import android.text.Editable;
  import android.text.TextWatcher;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.AdapterView;
  import android.widget.BaseAdapter;
  import android.widget.EditText;
  import android.widget.ListView;
  import android.widget.TextView;
  import android.widget.AdapterView.OnItemClickListener;
  
  public class SearchCocktail extends Activity{
  EditText ed;
  ListView lview; 
  
  String[] first = { "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight",     "Nine", "Ten"};
  
  String[] second = { "Uno", "Due", "Tre", "Quattro", "Cinque", "Sei", "Sette", "Otto",  "Nove", "Dieci"};
  
  int textlength = 0;
  ArrayList&lt;String&gt; first_sort = new ArrayList&lt;String&gt;();
  ArrayList&lt;String&gt; second_sort = new ArrayList&lt;String&gt;();
  
  public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  
  ed = (EditText) findViewById(R.id.editText1);
  lview = (ListView) findViewById(R.id.list);
  lview.setAdapter(new MyCustomAdapter(first, second));
  ...........
  public View getView(int position, View convertView, ViewGroup parent){
  
  LayoutInflater inflater = getLayoutInflater();
  View row;
  
  row = inflater.inflate(R.layout.listitem_row, parent, false);
  
  TextView textview = (TextView) row.findViewById(R.id.textView1);
  TextView textview1 = (TextView) row.findViewById(R.id.textView2);
  
  textview.setText(data_first[position]);
  textview1.setText(data_second[position]);
  
  return (row);
  }
  }
  
  @Override
  protected void onResume(){
  super.onResume();
  SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
  Editor editor = prefs.edit();
  
  String colorePref = prefs.getString(PreferencesFromXml.COLORE_PREF,  PreferencesFromXml.COLORE_DEFAULT);
  int coloreDiSfondo = Color.parseColor(colorePref);
  findViewById(R.id.list).setBackgroundColor(coloreDiSfondo);
  editor.commit();    
  }
  }
  </code></pre>
  
  <p>PreferencesFromXml activity:</p>
  
  <pre><code>import android.content.SharedPreferences;
  import android.content.SharedPreferences.Editor;
  import android.os.Bundle;
  import android.preference.Preference;
  import android.preference.Preference.OnPreferenceChangeListener;
  import android.preference.PreferenceActivity;
  import android.preference.PreferenceManager;
  
  public class PreferencesFromXml extends PreferenceActivity{
  
  public static final String COLORE_DEFAULT = "#000000";
  
  public static final String COLORE_PREF = "colore";
  
  public static final String TITOLO_PREF = "titolo";
  
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState)
  {
      super.onCreate(savedInstanceState);
  
      addPreferencesFromResource(R.xml.preferences);
  
      SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
      Editor editor = prefs.edit();
  
      Preference titoloPrefs = findPreference(TITOLO_PREF);
      titoloPrefs.setSummary(prefs.getString(TITOLO_PREF, getString(R.string.titolo_custom)));
      titoloPrefs.setOnPreferenceChangeListener(new OnPreferenceChangeListener()
      {
          public boolean onPreferenceChange(Preference prefs, Object value)
          {
              prefs.setSummary((CharSequence) value);
              return true;
          }
      });editor.commit();
  }
  }
  </code></pre>
  
  <p>With my code I can change background colour of layout main.xml but I want change also the TextView colour of listitem_row.xml. I'd like to change the colours together (example: black colour for background and white colour for the text or white colour for the background and black colour for the text, etc.). How can I proceed? Thanks to everyone who can answer.</p>