title: Android Selectors Text Color
body: <p>I've been over way too many StackOverflow questions and still can't get it working.</p>
  
  <p>I dynamically (programmatically) create a number of buttons on my activity. I need to use selectors to change the background and text color depending on if the button is pressed or not.</p>
  
  <p>I've got the background to change from black to white when its pressed, but I can't seem to get the text color to change (or set it for that matter ) - it just defaults to black.</p>
  
  <p>Here's what I've got.</p>
  
  <p>Java file:</p>
  
  <pre><code>monthButtons[i].setBackgroundResource(R.drawable.button_background);
  monthButtons[i].setTextColor(R.color.text_color);
  </code></pre>
  
  <p>button_background.xml:</p>
  
  <pre><code>&lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt;
  
      &lt;item android:state_pressed="true" 
          android:drawable="@color/white"/&gt;
  
      &lt;item android:drawable="@color/black"/&gt;        
  &lt;/selector&gt;
  </code></pre>
  
  <p>text_color.xml:</p>
  
  <pre><code>&lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;item android:state_pressed="true"
          android:textColor="@color/black" /&gt;
      &lt;item
          android:textColor="@color/white" /&gt;
   &lt;/selector&gt;
  </code></pre>
  
  <p>Can someone point me to a method to change the text color when the button is pressed? Please bear in mind I don't have anything defined in a layout file for these buttons.</p>
  
  <p>Thanks</p>