You can achieve this by use check box or ToggleButton. Below is an example
xml file
<CheckBox
android:id="@+id/check_on_of"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/chec_box_on_off"
/>
drawable chec_box_on_off file is
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/check_box_on" android:state_checked="true"/>
<item android:drawable="@drawable/check_box_off" android:state_checked="false"/>
</selector>
you will get like on off button and also you can check whether checkbox is on or off.
the java code is
CheckBox check = (CheckBox)findViewById(R.id.check_on_of);
check.isChecked();
Similarly, you can also achieve this using ToggleButton.
Switch
control. That's new in Ice Cream Sandwich (Android 4.0), so you are not able to use it in older versions. But since the source was released yesterday or so afaik you can have a look into it and see how it's done. Apart from that have a look at custom components. – Tassel