In Android, ToggleButton is just like a switch containing two states either ON or OFF which is represented using boolean values true and false respectively. ToggleButton unlike switch does not have a slider interface i.e we cannot slide to change the states. It is just like a button. In this article, we will be discussing how to create a ToggleButton in Kotlin dynamically.
Note: ToggleButton inherits the button class of android. Therefore, all the attributes of the button are also applicable here.
Following are some of the additional important attributes available along ToggleButton
It is used to adjust the alpha value of the button when it is disabled
The text which is shown when button is on or checked
The text which is shown when button is off or unchecked
Create a new project in Android Studio
To create a new project in Android Studio follow these steps:
Click on File, then New and then New Project and give name whatever you like.
Choose “Empty Activity” for the project template.
Then, select Kotlin language Support and click next button.
Select minimum SDK, whatever you need
This is how your project directory should look like:
Please Login to comment...