![]() |
VOOZH | about |
Toggle Buttons are used in most applications. These buttons are used to perform multiple operations. Toggle buttons are seen used in many social media applications such as Instagram. In social media apps, we can get to see a heart icon that is used to like the image. We can also unlike that image by clicking on the same icon. In this article, we will look at How to Create an Icon Toggle Button in Android using Jetpack Compose.
A sample gif is given below to get an idea about what we are going to do in this article.
To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. While choosing the template, select Empty Compose Activity. If you do not find this template, try upgrading the Android Studio to the latest version.
We demonstrated the application in Kotlin, so make sure you select Kotlin as the primary language while creating a New Project.
Go to the MainActivity.kt file and refer to the following code. Below is the code for the MainActivity.kt file. Comments are added inside the code to understand the code in more detail.
MainActivity.kt: