kotlin button
In this tutorial, we’ll learn how to create a Button in Android apps using Kotlin programming.
在本教程中,我们将学习如何使用Kotlin编程在Android应用程序中创建Button。
Android按钮概述 ()
Android Button class extends TextView. Button is a UI widget that is used to get click interactions from the user to trigger an action in the application.
Android Button类扩展了TextView。 Button是一个UI小部件,用于从用户获取点击交互以触发应用程序中的操作。
A button can be created in the XML layout as well as the Kotlin Activity class in the Android Studio Project.
可以在XML布局以及Android Studio项目中的Kotlin Activity类中创建一个按钮。
在XML布局中创建按钮 ()
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Androidly Button"/>
- android:id is used to set the unique identifier on the Button. android:id用于在Button上设置唯一标识符。
- The
android:text
is used to set the text inside the button. By default text is displayed in capital letters.android:text
用于在按钮内设置文本。 默认情况下,文本以大写字母显示。 android:onClick
is used to define the Kotlin function to be invoked in the activity when the button is clicked. It is a click listener.android:onClick
用于定义单击按钮时在活动中调用的Kotlin函数。 这是一个点击监听器。- The
android:background
is used to set the background color/drawable on the Button.android:background
用于在Button上设置背景颜色/可绘制。
android:textAllCaps="false"
android:textAllCaps="false"
For more details on how to customize your Buttons in XML Layout refer to the Android Buttons Tutorial.
有关如何在XML布局中自定义按钮的更多详细信息,