title: Change background using selector in android
body: <p>I need to change the background color of layout background based on click events. so created one selector and set background for layout.</p>
  
  <p>XML code: bg.xml</p>
  
  <pre><code>&lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;item android:state_pressed="true"
          android:drawable="@drawable/bg_tabselect" /&gt; &lt;!-- pressed --&gt;
      &lt;item android:state_focused="true"
          android:drawable="@drawable/bg_tabselect" /&gt; &lt;!-- focused --&gt;
      &lt;item android:drawable="@drawable/bg_tabunselect" /&gt; &lt;!-- default --&gt;
  &lt;/selector&gt;
  </code></pre>
  
  <p>Layout: layoutmain.xml</p>
  
  <pre><code>&lt;RelativeLayout
  android:id="@+id/layout"
  android:background="@drawable/bg.xml"&gt;
  &lt;Textview.../&gt;
  &lt;Textview.../&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Java : Main.java</p>
  
  <pre><code>   RelativeLayout layout=(RelativeLayout)view.findviewbyid(R.id.layout);
      layout.setonclicklisteners(this);
  
  
  
       @Override
          public void onClick(View v) {
              switch (v.getId()){
                  case R.id.layout:
                         Toast.makeText(getActivity(),"Selectedone",Toast.LENGTH_SHORT).show();
  
                      break;
              }
          }
  </code></pre>
  
  <p>Problem: </p>
  
  <blockquote>
    <p>1.when pressed on layout it working properly when remove press on layout again back to unselect color. How do solve this?<br>
    2. How to make first layout is default selection?</p>
  </blockquote>
  
  <p>thanks in advance...</p>