Android Toggle button example tutorial

Toggle button is like simple on off switch it is very useful for android apps because with the use of Toggle buttons you can start close any service set on toggle button with one click. So here is the complete step by step tutorial for Android Toggle button example tutorial.

android-project-download-code-button

Android Toggle button example tutorial.

Code for MainActivity.java file.

 package com.android_examples.com.togglebuttonexample;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ToggleButton;

public class MainActivity extends Activity {

 ToggleButton Tbutton;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 }
}

Code for activity_main.xml layout file.

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.android_examples.com.togglebuttonexample.MainActivity" >

 <ToggleButton
 android:id="@+id/toggleButton1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignParentTop="true"
 android:layout_centerHorizontal="true"
 android:layout_marginTop="66dp"
 android:text="ToggleButton" />

</RelativeLayout>

Screenshot:

Android Toggle button example tutorial

Click Here To Download Android Toggle button example tutorial Project.

Leave a Reply

Your email address will not be published. Required fields are marked *