title: Android: Change toggle button background color, indicating option enable or disabled options
body: <p>I have a toggle button, the back ground of which I would like to change when pressed. My objective is to change the color of the button even after the press event to a new color. When it is pressed again, it goes to initial state.</p>
  
  <p>I have used the following code, but in my case the color is not retained after the event of 'Press'. When the button is pressed the color changes. But However it reverts back to the original color of the button as soon as the press event ends. </p>
  
  <h3>Layout:</h3>
  
  <pre><code>&lt;ToggleButton android:id="@+id/price_activate_button" 
   android:layout_width="wrap_content" 
   android:textSize="15dp" 
   android:text="@string/string_price" 
   android:layout_alignParentLeft="true"
   android:layout_height="wrap_content" 
   android:background="@drawable/button_blue" 
   style="@style/ButtonText" 
   android:textOn="Price" 
   android:textOff="Price"&gt;&lt;/ToggleButton&gt;
  </code></pre>
  
  <h3>Style:</h3>
  
  <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_focused="true" 
    android:state_pressed="true"&gt;
  &lt;shape&gt;
  &lt;solid
   android:color="#859dbc" /&gt;
  &lt;stroke
   android:width="1dp"
   android:color="#859dbc" /&gt;
  &lt;corners
   android:radius="2dp" /&gt;
  &lt;padding
   android:left="5dp"
   android:top="5dp"
   android:right="5dp"
   android:bottom="5dp" /&gt;
  &lt;/shape&gt;
  &lt;/item&gt;
  &lt;item android:state_pressed="true" &gt;
  &lt;shape&gt;
  &lt;solid
   android:color="#859dbc" /&gt;
  &lt;stroke
   android:width="1dp"
   android:color="#859dbc" /&gt;
  &lt;corners
   android:radius="2dp" /&gt;
  &lt;padding
   android:left="5dp"
   android:top="5dp"
   android:right="5dp"
   android:bottom="5dp" /&gt;
  &lt;/shape&gt;
  &lt;/item&gt;
  &lt;item android:state_focused="true"  android:state_pressed="false" &gt;
  &lt;shape&gt;
  &lt;solid
   android:color="#2c68e7" /&gt;
  &lt;stroke
   android:width="1dp"
   android:color="#2c68e7" /&gt;
  &lt;corners
   android:radius="2dp" /&gt;
  &lt;padding
   android:left="5dp"
   android:top="5dp"
   android:right="5dp"
   android:bottom="5dp" /&gt;
  &lt;/shape&gt;
  &lt;/item&gt;          
  &lt;item android:state_checked="true"&gt;
  &lt;shape&gt;
  &lt;solid
   android:color="#2c68e7" /&gt;
  &lt;stroke
   android:width="1dp"
   android:color="#2c68e7" /&gt;
  &lt;corners
   android:radius="2dp" /&gt;
  &lt;padding
   android:left="5dp"
   android:top="5dp"
   android:right="5dp"
   android:bottom="5dp" /&gt;
  &lt;/shape&gt;
  &lt;/item&gt;
  &lt;item android:state_checked="false"&gt;
  &lt;shape&gt;
  &lt;solid
   android:color="#859dbc" /&gt;
  &lt;stroke
   android:width="1dp"
   android:color="#859dbc" /&gt;
  &lt;corners
   android:radius="2dp" /&gt;
  &lt;padding
   android:left="5dp"
   android:top="5dp"
   android:right="5dp"
   android:bottom="5dp" /&gt;
  &lt;/shape&gt;
  &lt;/item&gt;   
  &lt;/selector&gt;
  </code></pre>
  
  <h3>Activity Class:</h3>
  
  <pre><code>final ToggleButton price_button = (ToggleButton)findViewById(R.id.price_activate_button);
  
  price_button.setOnClickListener(new View.OnClickListener() {
      public void onClick(View v) {
          if(price_button.isChecked()){
              Toast.makeText(getApplicationContext(), "You have chosen: Yes", Toast.LENGTH_LONG).show();
          } else {
              Toast.makeText(getApplicationContext(), "You have chosen: No", Toast.LENGTH_LONG).show();
          }
      }
  });
  </code></pre>