To use Calendar DatePicker in activity_main.xml
In this file, we will add the DatePicker and Button widget and set their attributes so that it can be accessed in the kotlin file.
XML
< LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android" android:orientation = "vertical" android:layout_width = "match_parent" android:layout_height = "match_parent" android:id = "@+id/linear_layout" android:gravity = "center" > < DatePicker android:id = "@+id/date_Picker" android:layout_width = "match_parent" android:layout_height = "match_parent" /> </ LinearLayout > |
DatePicker in Kotlin
Android DatePicker is a user interface control which is used to select the date by day, month and year in our android application. DatePicker is used to ensure that the users will select a valid date.
In android DatePicker having two modes, first one to show the complete calendar and second one shows the dates in spinner view.
We can create a DatePicker control in two ways either manually in XML file or create it in Activity file programmatically.
First we create a new project by following the below steps:
- Click on File, then New => New Project.
- After that include the Kotlin support and click on next.
- Select the minimum SDK as per convenience and click next button.
- Then select the Empty activity => next => finish.
Contact Us