title: Change button android:background to different drawable
body: <p>I am new to Android and Java but have managed to teach myself and find most answers to questions on stackoverflow without needing to ask questions.  Until now....</p>
  
  <p>Here goes, I have many colored buttons which, when clicked, change color to a range of different colors.</p>
  
  <p>There are many buttons defined for example as:</p>
  
  <pre><code>&lt;Button
     android:id="@+id/button17"
     android:layout_width="0dp"
     android:layout_height="fill_parent"
     android:layout_weight="1"
     android:background="@drawable/orange_button"
     android:gravity="center"
     android:onClick="onClick" /&gt;
  </code></pre>
  
  <p>Could someone please advise me how to change the android:background using code to change the above example to yellow, for example, when the button is clicked.</p>
  
  <p>In the code below clickedButton is the ID of the button for which I need to change the background.</p>
  
  <pre><code>public void onClick(View v) {
      int id=v.getId();
      String clickedButton = getResources().getResourceEntryName(id);
  
      Change button to Yellow here??
  
      // Temporary code below to check which button was pressed
      // and convert its number to an integer to eventually access an array
  
      final TextView tvGameTimer = (TextView) findViewById(R.id.tvGameTimer);
      int buttonNumber = Integer.parseInt(clickedButton.substring(6,8));
      tvGameTimer.setText("" + buttonNumber);
  
      }
  </code></pre>
  
  <p>I am using custom button styles to define the button colors:</p>
  
  <pre><code>res/drawable/yellow_button.xml
  res/drawable/blue_button.xml
  res/drawable/red_button.xml
  res/drawable/orange_button.xml
  res/drawable/green_button.xml
  </code></pre>
  
  <p>For now I just need to work out how to change the button from Orange to Yellow. I can then add the logic to change the colors as and when the app requires.</p>
  
  <p>Many thanks for any help.</p>