<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ToggleButton
android:id="@+id/toggleButton01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/btn_default"
android:textOff="Off Stage"
android:textOn="On Stage" />
</LinearLayout>
package com.button;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ToggleButton;
public class ButtonActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final ToggleButton tb =
(ToggleButton)this.findViewById(R.id.toggleButton01);
tb.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (tb.isChecked()) {
tb.setBackgroundDrawable(getResources().
getDrawable(R.drawable.btn_press));
} else {
tb.setBackgroundDrawable(getResources().
getDrawable(R.drawable.btn_select));
}
}
});
}
}

