Hello Readers! In this post, we will learn about Android Button using kotlin. We will also go through different attributes that are used commonly.
Android Button is an user interface that are used to perform some action when clicked or tapped.
Different attributes of Android Button Widget are listed below. However, If you want to know more attributes you can visit android official documentation on Button Widget.
1 android:background This attribute is used to set background to this View.
2 android:backgroundTint This attribute is used to set tint to the background.
3 android:clickable This attribute is used to set true when you want to make this View clickable. Otherwise, set false.
4 android:drawableBottom This is drawable to be drawn at bottom of the text.
5 android:drawableEnd This is drawable to be drawn to end of the text.
6 android:drawableLeft This is drawable to be drawn to left of the text.
7 android:drawablePadding This is padding of the drawable.
8 android:drawableRight This is drawable to be drawn to right of the text.
9 android:drawableStart This is drawable to be drawn to start of the text.
10 android:drawableTop This is drawable to be drawn at top of the text.
11 android:text Sets the text of the EditText.
12 android:textAllCaps Shows text in capital letters.
13 android:textColor Sets color of the text.
14 android:textSize Sets size of the text.
15 android:textStyle Sets style of the text. For example, bold, italic, bolditalic etc.
16 android:typeface Sets typeface of the text. For example, normal, sans, serif, monospace.
In this section, we will learn how to use Android Button using kotlin in any android application. At first, we will create an android application. Then, we will use Android Button using kotlin.
Follow steps below to create android application. Please ignore the steps if you have already created android application.
2. Go to File => New => New Project. Write application name as Button. Then, check Include Kotlin Support and click next button.
You can also visit post to get detailed steps to create new project in android. The topics are covered in java. However, the steps are similar in kotllin.
Now, we will modify xml and kotlin file to use Button in the application.
Other values folders have not been changed. So, we are not going to mention it here.
Here, we have defined Button in xml file. Now, we will access this Button in kotlin file. Then, we will show a Toast message when this Button is clicked.
Open src/main/java/com.tutorialwing.edittext/MainActivity.kt file. Then, add below code into it.
Since AndroidManifest file is very important part of any android application, we are also going to mention it here.
That’s end of tutorial on Android Button using Kotlin.