title: Android Change background color when clicked
body: <p>I'm trying to change the background color of a <code>Button</code> when it is clicked, I can change the background color when I have the <code>Button</code> pressed down when I release the <code>Button</code> the button returns to its default color. I'm not sure where to go from here I have been trying to find a solution to this problem.</p>
  
  <p>`</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context="com.example.game.dice.MainActivity"&gt;
  
      &lt;Button
          android:id="@+id/but1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Button 1"
          android:background="@drawable/button_color"
          /&gt;
      &lt;Button
          android:id="@+id/but2"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Button 2"
          android:background="@drawable/button_color"/&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>`</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt;
  &lt;item android:state_pressed="true"
      android:drawable="@color/button_pressed"/&gt;
  &lt;item android:state_focused="true"
      android:drawable="@color/button_focused"/&gt; 
  &lt;item android:drawable="@color/button_default"/&gt; 
  &lt;/selector&gt;
  </code></pre>