{"id":989,"date":"2022-07-14T12:39:02","date_gmt":"2023-11-13T11:04:08","guid":{"rendered":"https:\/\/www.silicloud.com\/blog\/uncategorized\/example-of-an-android-toggle-button-switch\/"},"modified":"2025-07-18T14:34:28","modified_gmt":"2025-07-18T14:34:28","slug":"toggle-button-in-android","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/blog\/toggle-button-in-android\/","title":{"rendered":"Toggle button in Android"},"content":{"rendered":"<p>Today, our focus will be on the Android Toggle Button and Switch within an Android application. We will delve into the Switch button Widget and the ToggleButton widget, exploring their functionality and implementing them in our app.<\/p>\n<h2>Toggle button in <a href=\"https:\/\/en.wikipedia.org\/wiki\/Android_(operating_system)\">Android<\/a><\/h2>\n<p>The Android Toggle Button is utilized to exhibit the on and off state on a button. Another kind of toggle button, the Switch, is primarily employed on Android devices with version 4.0 and above. The Android Switch offers a slider control. Both the ToggleButton and Switch are derived from the CompoundButton class. The XML attributes employed to define a ToggleButton are explained below.<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>android:disabledAlpha: The level of transparency to be applied to the indicator when disabled<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>android:textOff: The content displayed on the button when it is unchecked<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>android:textOn: The content displayed on the button when it is checked<\/ol>\n<p>The ToggleButton is programmatically modified using the following methods.<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>Please provide one option for paraphrasing:<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>&#8211; The method getTextOff() returns the text displayed when the button is not checked.<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>&#8211; The method getTextOn() returns the text displayed when the button is checked.<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>&#8211; The method setChecked(boolean checked) allows for changing the button&#8217;s checked state.<\/ol>\n<h3>Switch on <a href=\"https:\/\/en.wikipedia.org\/wiki\/Android_(operating_system)\">Android<\/a><\/h3>\n<p>The Android Switch or SwitchCompat widget, which is a component of the AppCompat library, offers backward compatibility for Android versions older than Android API v7. It presents a customized slider for enabling or disabling functions, commonly observed in phone settings. The Android Switch Widget provides several benefits.<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>It is the ultimate alternative for checkboxes and RadioButtons<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\n<li style=\"list-style-type: none\">\n<ol>Implementation can be done in less than a minute<\/ol>\n<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>Little to no requirement for drawables and other resources<\/ol>\n<p>Here is the provided XML layout for a SwitchCompat:<\/p>\n<pre class=\"post-pre\"><code>&lt;android.support.v7.widget.SwitchCompat\r\n        android:id=\"@+id\/switchButton\"\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:textAppearance=\"?android:attr\/textAppearanceMedium\"\r\n        android:text=\"Switch example\"\r\n        \/&gt;\r\n<\/code><\/pre>\n<p>The android:text property is utilized to show a Text alongside the switch button of the slider.<\/p>\n<h3>Example of a Toggle Button and Switch in Android<\/h3>\n<p>We will show two ToggleButtons and one Switch button in this app. When the FloatingActionButton is pressed, the states of the Toggle Buttons will be shown in a SnackBar. If the action button on the SnackBar is clicked, the state of the Switch button will be changed to true. Alternatively, the state can be displayed in the SnackBar by sliding the switch.<\/p>\n<h3>Project Structure of Android Toggle Button and Switch<\/h3>\n<h3>Code for an Android toggle button<\/h3>\n<p>In the activity_main.xml, there are no changes. The content_main.xml includes two Toggle Buttons and a Switch that are initially unchecked, according to the following code snippet.<\/p>\n<pre class=\"post-pre\"><code>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;RelativeLayout xmlns:android=\"https:\/\/schemas.android.com\/apk\/res\/android\"\r\n    xmlns:app=\"https:\/\/schemas.android.com\/apk\/res-auto\"\r\n    xmlns:tools=\"https:\/\/schemas.android.com\/tools\"\r\n    android:layout_width=\"match_parent\"\r\n    android:layout_height=\"match_parent\"\r\n    android:paddingBottom=\"@dimen\/activity_vertical_margin\"\r\n    android:paddingLeft=\"@dimen\/activity_horizontal_margin\"\r\n    android:paddingRight=\"@dimen\/activity_horizontal_margin\"\r\n    android:paddingTop=\"@dimen\/activity_vertical_margin\"\r\n    app:layout_behavior=\"@string\/appbar_scrolling_view_behavior\"\r\n    tools:context=\"com.scdev.switchandtoggle.MainActivity\"\r\n    tools:showIn=\"@layout\/activity_main\"&gt;\r\n\r\n    &lt;ToggleButton\r\n        android:id=\"@+id\/tb1\"\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:layout_alignParentLeft=\"true\"\r\n        android:layout_alignParentTop=\"true\"\r\n        android:text=\"ToggleButton 1\"\r\n        android:textOff=\"Off\"\r\n        android:textOn=\"On\" \/&gt;\r\n\r\n    &lt;ToggleButton\r\n        android:id=\"@+id\/tb2\"\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:layout_alignBaseline=\"@+id\/tb1\"\r\n        android:layout_alignBottom=\"@+id\/tb1\"\r\n        android:layout_toRightOf=\"@+id\/tb1\"\r\n        android:text=\"ToggleButton 2\"\r\n        android:textOff=\"Off\"\r\n        android:textOn=\"On\" \/&gt;\r\n\r\n    &lt;android.support.v7.widget.SwitchCompat\r\n        android:id=\"@+id\/switchButton\"\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_centerInParent=\"true\"\r\n        android:checked=\"false\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:textAppearance=\"?android:attr\/textAppearanceMedium\"\r\n        android:text=\"Switch example\"\r\n        \/&gt;\r\n\r\n\r\n&lt;\/RelativeLayout&gt;\r\n<\/code><\/pre>\n<p>Below is the code for the MainActivity.java.<\/p>\n<pre class=\"post-pre\"><code>package com.scdev.switchandtoggle;\r\n\r\nimport android.graphics.Color;\r\nimport android.os.Bundle;\r\nimport android.support.design.widget.FloatingActionButton;\r\nimport android.support.design.widget.Snackbar;\r\nimport android.support.v7.app.AppCompatActivity;\r\nimport android.support.v7.widget.SwitchCompat;\r\nimport android.support.v7.widget.Toolbar;\r\nimport android.view.View;\r\nimport android.view.Menu;\r\nimport android.view.MenuItem;\r\nimport android.widget.CompoundButton;\r\nimport android.widget.ToggleButton;\r\n\r\npublic class MainActivity extends AppCompatActivity {\r\n\r\n    ToggleButton tb1, tb2;\r\n    SwitchCompat switchCompat;\r\n\r\n    @Override\r\n    protected void onCreate(Bundle savedInstanceState) {\r\n        super.onCreate(savedInstanceState);\r\n        setContentView(R.layout.activity_main);\r\n        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);\r\n        setSupportActionBar(toolbar);\r\n\r\n        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);\r\n        fab.setOnClickListener(new View.OnClickListener() {\r\n            @Override\r\n            public void onClick(View view) {\r\n\r\n                StringBuilder result = new StringBuilder();\r\n                result.append(\"ToggleButton1 : \").append(tb1.getText());\r\n                result.append(\"\\nToggleButton2 : \").append(tb2.getText());\r\n\r\n               Snackbar snackbar= Snackbar.make(view, result.toString(), Snackbar.LENGTH_LONG)\r\n                        .setAction(\"SWITCH ENABLE\", new View.OnClickListener() {\r\n                            @Override\r\n                            public void onClick(View v) {\r\n                                switchCompat.setChecked(true);\r\n                            }\r\n                        });\r\n\r\n                snackbar.setActionTextColor(Color.RED);\r\n                snackbar.show();\r\n            }\r\n        });\r\n\r\n        tb1= (ToggleButton)findViewById(R.id.tb1);\r\n        tb2=(ToggleButton)findViewById(R.id.tb2);\r\n        switchCompat=(SwitchCompat)findViewById(R.id.switchButton);\r\n\r\n        switchCompat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {\r\n            @Override\r\n            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {\r\n\r\n                Snackbar.make(buttonView, \"Switch state checked \"+isChecked, Snackbar.LENGTH_LONG)\r\n                        .setAction(\"ACTION\",null).show();\r\n            }\r\n        });\r\n\r\n\r\n\r\n    }\r\n\r\n    @Override\r\n    public boolean onCreateOptionsMenu(Menu menu) {\r\n        \/\/ Inflate the menu; this adds items to the action bar if it is present.\r\n        getMenuInflater().inflate(R.menu.menu_main, menu);\r\n        return true;\r\n    }\r\n\r\n    @Override\r\n    public boolean onOptionsItemSelected(MenuItem item) {\r\n        \/\/ Handle action bar item clicks here. The action bar will\r\n        \/\/ automatically handle clicks on the Home\/Up button, so long\r\n        \/\/ as you specify a parent activity in AndroidManifest.xml.\r\n        int id = item.getItemId();\r\n\r\n        \/\/noinspection SimplifiableIfStatement\r\n        if (id == R.id.action_settings) {\r\n            return true;\r\n        }\r\n\r\n        return super.onOptionsItemSelected(item);\r\n    }\r\n}\r\n<\/code><\/pre>\n<p>To obtain the current status of the toggle buttons and add them to be shown in the snackbar, a StringBuilder is utilized. By implementing an OnCheckChangeListener, the subclass of Compound Button, the switch button is implemented as demonstrated in the aforementioned code. The resulting display of the application can be observed below. Thus, we conclude this tutorial on Android toggle button and switch in Android. For access to the final Android SwitchAndToggle Project, please refer to the provided link.<\/p>\n<p>Please download the Android Switch and Toggle Button Project.<\/p>\n<p>Source: ToggleButton Android Documentation<\/p>\n<p>Paraphrased: Documentation for ToggleButton in Android API.<\/p>\n<p>&nbsp;<\/p>\n<p>other tutorials<\/p>\n<p><a class=\"LinkSuggestion__Link-sc-1gewdgc-4 cLBplk\" href=\"https:\/\/www.silicloud.com\/blog\/broadcastreceiver-android-tutor\/\" target=\"_blank\" rel=\"noopener\">BroadcastReceiver Example Tutorial on Android<span class=\"sc-gswNZR eASTkv\">(Opens in a new browser tab)<\/span><\/a><\/p>\n<p><a class=\"LinkSuggestion__Link-sc-1gewdgc-4 cLBplk\" href=\"https:\/\/www.silicloud.com\/blog\/tutorial-on-hibernate-tomcat-jndi-datasource\/\" target=\"_blank\" rel=\"noopener\">Tutorial on how to set up a Hibernate Tomcat JNDI DataSource.<span class=\"sc-gswNZR eASTkv\">(Opens in a new browser tab)<\/span><\/a><\/p>\n<p><a class=\"LinkSuggestion__Link-sc-1gewdgc-4 cLBplk\" href=\"https:\/\/www.silicloud.com\/blog\/qr-code-generator-in-java-using-zxing\/\" target=\"_blank\" rel=\"noopener\">QR code generator in Java using zxing.<span class=\"sc-gswNZR eASTkv\">(Opens in a new browser tab)<\/span><\/a><\/p>\n<p><a class=\"LinkSuggestion__Link-sc-1gewdgc-4 cLBplk\" href=\"https:\/\/www.silicloud.com\/blog\/java-thread-ensuring-safety\/\" target=\"_blank\" rel=\"noopener\">Java thread ensuring Java code is thread-safe<span class=\"sc-gswNZR eASTkv\">(Opens in a new browser tab)<\/span><\/a><\/p>\n<p><a class=\"LinkSuggestion__Link-sc-1gewdgc-4 cLBplk\" href=\"https:\/\/www.silicloud.com\/blog\/spring-mvc-handlerinterceptoradapter-and-handlerinterceptor\/\" target=\"_blank\" rel=\"noopener\">Spring MVC HandlerInterceptorAdapter and HandlerInterceptor.<span class=\"sc-gswNZR eASTkv\">(Opens in a new browser tab)<\/span><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today, our focus will be on the Android Toggle Button and Switch within an Android application. We will delve into the Switch button Widget and the ToggleButton widget, exploring their functionality and implementing them in our app. Toggle button in Android The Android Toggle Button is utilized to exhibit the on and off state on [&hellip;]<\/p>\n","protected":false},"author":14,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[1],"tags":[13,120,115,112,118,116,117,119,114,113],"class_list":["post-989","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-android-development","tag-android-programming","tag-android-switch","tag-android-toggle-button","tag-android-tutorial","tag-android-ui","tag-android-widgets","tag-compoundbutton","tag-switchcompat","tag-togglebutton"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Toggle button in Android - Blog - Silicon Cloud<\/title>\n<meta name=\"description\" content=\"Toggle Button is utilized to exhibit the on and off state on a button. Both the ToggleButton and Switch are derived fromLearn how to implement Android toggle button and switch widgets in your app. Complete tutorial with ToggleButton and SwitchCompat examples, XML layouts, and Java code for beginners.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/blog\/toggle-button-in-android\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Toggle button in Android\" \/>\n<meta property=\"og:description\" content=\"Toggle Button is utilized to exhibit the on and off state on a button. Both the ToggleButton and Switch are derived fromLearn how to implement Android toggle button and switch widgets in your app. Complete tutorial with ToggleButton and SwitchCompat examples, XML layouts, and Java code for beginners.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/blog\/toggle-button-in-android\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/SiliCloudGlobal\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-11-13T11:04:08+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-07-18T14:34:28+00:00\" \/>\n<meta name=\"author\" content=\"Noah Thompson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@SiliCloudGlobal\" \/>\n<meta name=\"twitter:site\" content=\"@SiliCloudGlobal\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Noah Thompson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/toggle-button-in-android\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/toggle-button-in-android\/\"},\"author\":{\"name\":\"Noah Thompson\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/2e83cc6ab9f60d36921c2d0f9f280f4a\"},\"headline\":\"Toggle button in Android\",\"datePublished\":\"2023-11-13T11:04:08+00:00\",\"dateModified\":\"2025-07-18T14:34:28+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/toggle-button-in-android\/\"},\"wordCount\":601,\"publisher\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\"},\"keywords\":[\"Android development\",\"Android programming\",\"Android Switch\",\"Android toggle button\",\"Android tutorial\",\"Android UI\",\"Android widgets\",\"CompoundButton\",\"SwitchCompat\",\"ToggleButton\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/toggle-button-in-android\/\",\"url\":\"https:\/\/www.silicloud.com\/blog\/toggle-button-in-android\/\",\"name\":\"Toggle button in Android - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#website\"},\"datePublished\":\"2023-11-13T11:04:08+00:00\",\"dateModified\":\"2025-07-18T14:34:28+00:00\",\"description\":\"Toggle Button is utilized to exhibit the on and off state on a button. Both the ToggleButton and Switch are derived fromLearn how to implement Android toggle button and switch widgets in your app. Complete tutorial with ToggleButton and SwitchCompat examples, XML layouts, and Java code for beginners.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/toggle-button-in-android\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/blog\/toggle-button-in-android\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/toggle-button-in-android\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.silicloud.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Toggle button in Android\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/blog\/\",\"name\":\"Silicon Cloud Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\",\"name\":\"Silicon Cloud Blog\",\"url\":\"https:\/\/www.silicloud.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png\",\"contentUrl\":\"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png\",\"width\":1024,\"height\":1024,\"caption\":\"Silicon Cloud Blog\"},\"image\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/SiliCloudGlobal\/\",\"https:\/\/twitter.com\/SiliCloudGlobal\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/2e83cc6ab9f60d36921c2d0f9f280f4a\",\"name\":\"Noah Thompson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/350e537e1530ede2762ee0237e877d6693f4f7163ab4f303202cc9a6b27b6cb4?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/350e537e1530ede2762ee0237e877d6693f4f7163ab4f303202cc9a6b27b6cb4?s=96&d=mm&r=g\",\"caption\":\"Noah Thompson\"},\"url\":\"https:\/\/www.silicloud.com\/blog\/author\/noahthompson\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Toggle button in Android - Blog - Silicon Cloud","description":"Toggle Button is utilized to exhibit the on and off state on a button. Both the ToggleButton and Switch are derived fromLearn how to implement Android toggle button and switch widgets in your app. Complete tutorial with ToggleButton and SwitchCompat examples, XML layouts, and Java code for beginners.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/blog\/toggle-button-in-android\/","og_locale":"en_US","og_type":"article","og_title":"Toggle button in Android","og_description":"Toggle Button is utilized to exhibit the on and off state on a button. Both the ToggleButton and Switch are derived fromLearn how to implement Android toggle button and switch widgets in your app. Complete tutorial with ToggleButton and SwitchCompat examples, XML layouts, and Java code for beginners.","og_url":"https:\/\/www.silicloud.com\/blog\/toggle-button-in-android\/","og_site_name":"Blog - Silicon Cloud","article_publisher":"https:\/\/www.facebook.com\/SiliCloudGlobal\/","article_published_time":"2023-11-13T11:04:08+00:00","article_modified_time":"2025-07-18T14:34:28+00:00","author":"Noah Thompson","twitter_card":"summary_large_image","twitter_creator":"@SiliCloudGlobal","twitter_site":"@SiliCloudGlobal","twitter_misc":{"Written by":"Noah Thompson","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.silicloud.com\/blog\/toggle-button-in-android\/#article","isPartOf":{"@id":"https:\/\/www.silicloud.com\/blog\/toggle-button-in-android\/"},"author":{"name":"Noah Thompson","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/2e83cc6ab9f60d36921c2d0f9f280f4a"},"headline":"Toggle button in Android","datePublished":"2023-11-13T11:04:08+00:00","dateModified":"2025-07-18T14:34:28+00:00","mainEntityOfPage":{"@id":"https:\/\/www.silicloud.com\/blog\/toggle-button-in-android\/"},"wordCount":601,"publisher":{"@id":"https:\/\/www.silicloud.com\/blog\/#organization"},"keywords":["Android development","Android programming","Android Switch","Android toggle button","Android tutorial","Android UI","Android widgets","CompoundButton","SwitchCompat","ToggleButton"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/blog\/toggle-button-in-android\/","url":"https:\/\/www.silicloud.com\/blog\/toggle-button-in-android\/","name":"Toggle button in Android - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/blog\/#website"},"datePublished":"2023-11-13T11:04:08+00:00","dateModified":"2025-07-18T14:34:28+00:00","description":"Toggle Button is utilized to exhibit the on and off state on a button. Both the ToggleButton and Switch are derived fromLearn how to implement Android toggle button and switch widgets in your app. Complete tutorial with ToggleButton and SwitchCompat examples, XML layouts, and Java code for beginners.","breadcrumb":{"@id":"https:\/\/www.silicloud.com\/blog\/toggle-button-in-android\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/blog\/toggle-button-in-android\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/blog\/toggle-button-in-android\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.silicloud.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Toggle button in Android"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/blog\/#website","url":"https:\/\/www.silicloud.com\/blog\/","name":"Silicon Cloud Blog","description":"","publisher":{"@id":"https:\/\/www.silicloud.com\/blog\/#organization"},"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.silicloud.com\/blog\/#organization","name":"Silicon Cloud Blog","url":"https:\/\/www.silicloud.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png","contentUrl":"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png","width":1024,"height":1024,"caption":"Silicon Cloud Blog"},"image":{"@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/SiliCloudGlobal\/","https:\/\/twitter.com\/SiliCloudGlobal"]},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/2e83cc6ab9f60d36921c2d0f9f280f4a","name":"Noah Thompson","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/350e537e1530ede2762ee0237e877d6693f4f7163ab4f303202cc9a6b27b6cb4?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/350e537e1530ede2762ee0237e877d6693f4f7163ab4f303202cc9a6b27b6cb4?s=96&d=mm&r=g","caption":"Noah Thompson"},"url":"https:\/\/www.silicloud.com\/blog\/author\/noahthompson\/"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/989","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/users\/14"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/comments?post=989"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/989\/revisions"}],"predecessor-version":[{"id":1666,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/989\/revisions\/1666"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/media?parent=989"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/categories?post=989"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/tags?post=989"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}