![]() |
In Android, Button is a very common UI element that is used to call a function or perform a task when clicked by the user. A Button by default occupies specific space depending upon the text that it displays. If the Button text is longer or has a larger font size, the Button width, and height increase. Similarly, if the Button text is smaller or has a smaller font size, the Button width and height decrease. However, we can set pre-defined width and height to a Button irrespective of the text attributes. So in this article, we will show you how you could change the Button size in Android using Jetpack Compose. Follow the below steps once the IDE is ready. Step by Step ImplementationStep 1: Create a New Project in Android Studio 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. Step 2: Working with the MainActivity.kt file 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. Kotlin
Output: When you run the application, you will see three buttons of different fixed sizes as shown in the below image. |
Reffered: https://www.geeksforgeeks.org
Android |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 10 |