I need to change the background color of layout background based on click events. so created one selector and set background for layout.

XML code: bg.xml

```
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true"
        android:drawable="@drawable/bg_tabselect" /> <!-- pressed -->
    <item android:state_focused="true"
        android:drawable="@drawable/bg_tabselect" /> <!-- focused -->
    <item android:drawable="@drawable/bg_tabunselect" /> <!-- default -->
</selector>

```

Layout: layoutmain.xml

```
<RelativeLayout
android:id="@+id/layout"
android:background="@drawable/bg.xml">
<Textview.../>
<Textview.../>
</RelativeLayout>

```

Java : Main.java

```
   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;
            }
        }

```

Problem: 

> 
> 1.when pressed on layout it working properly when remove press on layout again back to unselect color. How do solve this?  
> 
>  2. How to make first layout is default selection?
> 
> 
> 

thanks in advance...