Androidではボタンを押した場合や離した場合と、ボタンの状態によって背景をダイナミックに変えることができます。
これは「State List」というリソースを使うことで簡単に実現できます。
あらかじめボタンに使う画像ファイルを/res/drawableに追加しておきます。
次に/res/drawableにbutton.xmlというxmlファイルを作ります。
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- pressed -->
<item
android:state_pressed="true"
android:drawable="@drawable/lilastoy" />
<!-- released -->
<item
android:state_pressed="false"
android:drawable="@drawable/toothtoy" />
</selector>
state_pressedがtrueもしくはfalse、つまりボタンが押されている、押されていないという状態ごとに
drawableで指定する画像ファイルを変えています。
あとは、ボタンビューの背景にbutton.xmlを指定すればOKです。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/button" />
/>
</LinearLayout>
これを動作させると以下の画像のようになります。