![]() |
VOOZH | about |
In Android applications, a Button is a user interface that is used to perform some action when clicked or tapped. It is a very common widget in Android and developers often use it. This article demonstrates how to create a button in Android Studio.
kotlin.Any
↳ android.view.View
↳ android.widgets.TextView
↳ android.widget.Button
XML Attributes | Description |
|---|---|
| android:id | Used to specify the id of the view. |
| android:text | Used to the display text of the button. |
| android:textColor | Used to the display color of the text. |
| android:textSize | Used to the display size of the text. |
| android:textStyle | Used to the display style of the text like Bold, Italic, etc. |
| android:textAllCaps | Used to display text in Capital letters. |
| android:background | Used to set the background of the view. |
| android:padding | Used to set the padding of the view. |
| android:visibility | Used to set the visibility of the view. |
| android:gravity | Used to specify the gravity of the view like center, top, bottom, etc |
In this example step by step demonstration of creating a Button will be covered. The application will consist of a button that displays a toast message when the user taps on it.
Add a button widget in the layout of the activity. Below is the code of the activity_main.xml file which does the same.
Add functionality of button in the MainActivity file. Here describe the operation to display a Toast message when the user taps on the button. Below is the code to carry out this task.