This is pretty easy. Here is the solution.
You have a TextView element with its background attribute set to @drawable/tbselectoras follows.
<TextView android:text="My text"
android:id="@+id/tv01"
android:layout_width="300dip"
android:layout_height="150dip"
android:layout_gravity="center_horizontal"
android:background="@drawable/tbselector"/>
The last attribute android:backgroundis essential for you.
Now you are creating tbselector.xmlin a subdirectory drawable. It looks like this.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/bgdefault"
android:state_focused="false"
android:state_selected="false"/>
<item
android:drawable="@drawable/bgselected"
android:state_focused="true"
android:state_selected="false"/>
</selector>
Now you create bgdefault.xmlin a subdirectory drawablethat looks like this.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size
android:width="200dip"
android:height="150dip"
android:color="#00FF00"/>
<solid
android:color="#00FF00"/>
</shape>
, bgselected.xml drawable, , , .
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size
android:width="200dip"
android:height="150dip"
android:color="#FFFF00"/>
<solid
android:color="#FFFF00"/>
</shape>
, TextView. , XML . - , .
, .