Add IOS like date time picker in your app. Get rid android date and time picker with single Widget to receive both date and time.
dependencies {
implementation 'com.github.abdulrehmank7:iOS-date-time-picker:1.05'
}
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
We can use IOS-Date-Time-Picker
without any customized attributes.
val startDate: Calendar = Calendar.getInstance()
val dateTimeSelectedListener = object :
OnDateTimeSelectedListener {
override fun onDateTimeSelected(selectedDateTime: Calendar) {
//This is the calendar reference of selected date and time.
//We can format the date time as we need here.
println("Selected date ${selectedDateTime.time}")
}
}
val dateTimePickerDialog = DialogDateTimePicker(
this, //context
startDate, //start date of calendar
12, //No. of future months to shown in calendar
dateTimeSelectedListener,
"Select date and time") //Dialog title
//To show the date time picker dialog
dateTimePickerDialog.show()
dateTimePickerDialog.setTitleTextColor(android.R.color.black)
dateTimePickerDialog.setDividerBgColor(android.R.color.black)
dateTimePickerDialog.setCancelBtnColor(R.color.colorAccent)
dateTimePickerDialog.setCancelBtnTextColor(R.color.colorPrimaryDark)
dateTimePickerDialog.setSubmitBtnColor(R.color.colorAccent)
dateTimePickerDialog.setSubmitBtnTextColor(R.color.colorPrimaryDark)
dateTimePickerDialog.setCancelBtnText("Dismiss")
dateTimePickerDialog.setSubmitBtnText("OK")
dateTimePickerDialog.setFontSize(14)
dateTimePickerDialog.setCenterDividerHeight(38)
//Call dateTimePickerDialog.show() after all the customization is set on dialog.
//So dateTimePickerDialog.show() will be called last.