Button in Android using Jetpack Compose
Jetpack Compose is a new toolkit provided by Google. This is useful for designing beautiful UI designs. A Button is a UI component in Android which is used to navigate between different screens and with the help of button user can interact with your app. With the help of a button, the user can perform multiple actions inside your application. In this article, we will take a look at the implementation of buttons in Android using Jetpack compose.
Attributes of the Button Widget
|onClick||To perform an action when your button is clicked by the app user.|
|modifier||this parameter is used to add padding to our button.|
|enabled||to enable or disable your button.|
|border||this parameter is used to add border stroke to our button.|
|shape||this parameter is used to add shape to our button.|
|Text()||this parameter will be used to add text which is to be displayed on your button.|
Step by Step Implementation
Step 1: Create a New Project.
To create a new project in the Android Studio Canary Version please refer to How to Create a new Project in Android Studio Canary Version with Jetpack Compose.
Step 2: Working with the MainActivity.kt file
Navigate to the app > java > your app’s package name and open the MainActivity.kt file. Inside that file add the below code to it. Comments are added inside the code to understand the code in more detail.