91-9990449935 0120-4256464 |
Android ToggleButton ExampleAndroid Toggle Button can be used to display checked/unchecked (On/Off) state on the button. It is beneficial if user have to change the setting between two states. It can be used to On/Off Sound, Wifi, Bluetooth etc. Since Android 4.0, there is another type of toggle button called switch that provides slider control. Android ToggleButton and Switch both are the subclasses of CompoundButton class. Android ToggleButton classToggleButton class provides the facility of creating the toggle button. XML Attributes of ToggleButton classThe 3 XML attributes of ToggleButton class.
Methods of ToggleButton classThe widely used methods of ToggleButton class are given below.
Android ToggleButton Exampleactivity_main.xmlDrag two toggle button and one button for the layout. Now the activity_main.xml file will look like this: File: activity_main.xml
Activity classLet's write the code to check which toggle button is ON/OFF. File: MainActivity.java
Output:
Next TopicAndroid Checkbox Example
|