title: How to set rounded buttons with background color and change color on pressed
body: <p>In my android app there is a rounded rectangle button with green colored background.
  i did this using .xml file </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;shape xmlns:android="http://schemas.android.com/apk/res/android"
  android:padding="10dp"
  android:shape="rectangle" &gt;
  
  &lt;solid android:color="#B5D397" /&gt;
  
  &lt;corners
      android:bottomLeftRadius="10dp"
      android:bottomRightRadius="10dp"
      android:topLeftRadius="10dp"
      android:topRightRadius="10dp" /&gt;
  
  
  &lt;/shape&gt;
  </code></pre>
  
  <p>and</p>
  
  <pre><code> android:background="@drawable/rounded_btn"
  </code></pre>
  
  <p>in layout file</p>
  
  <p>but when i press button is wasn't showing any effect(no change is color) so i used</p>
  
  <pre><code>@Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
              Button view = (Button) v;
               view.getBackground().setColorFilter(0x77000000, PorterDuff.Mode.SRC_ATOP);
  </code></pre>
  
  <p>and color of button changes to dark green after pressing it. Till here everything is working fine, but problem is after releasing button color remains dark green. i want it to be like as it was before pressing.I referred few examples which says to use <strong>selector</strong> in .xml file i.e</p>
  
  <pre><code>&lt;selector xmlns:android="http://schemas.android.com/apk/res/android" &gt;
      &lt;item
          android:color="#c0c0c0"
          android:state_selected="true"/&gt;
      &lt;item
          android:color="#ffffff"
          android:state_pressed="true"/&gt;
      &lt;item
          android:color="#9A9A9A"
          android:state_focused="false"
          android:state_pressed="false"
          android:state_selected="false"/&gt;
  &lt;/selector&gt;
  </code></pre>
  
  <p>Which also needs <strong><code>android:background="@drawable/btn_state"</code></strong>
  but i have already used <strong><code>android:background=@drawable/rounded_btn</code></strong> </p>
  
  <p>So how to give both effect together</p>
  
  <p>i also tried using <strong><code>OnTouchListener</code></strong> </p>
  
  <pre><code>button.setOnTouchListener(new OnTouchListener() {
  @Override
  public boolean onTouch(View v, MotionEvent event) {
   // show interest in events resulting from ACTION_DOWN
   if(event.getAction()==MotionEvent.ACTION_DOWN) return true;
   // don't handle event unless its ACTION_UP so "doSomething()" only runs once.
   if(event.getAction()!=MotionEvent.ACTION_UP) return false;
   doSomething();
    button.setPressed(true);                   
    return true;
  }
  });
  </code></pre>
  
  <p>but this disables my <strong><code>OnclickListener()</code></strong> method and i dont want to use <strong><code>OnTouchListener()</code></strong></p>
  
  <p>i know this is silly but i am new to android
  thanks a lot</p>