androidkotlintimepickerdialog

Title in TimePickerDialog


I'm trying to set a title to my TimePickerDialog. I've seen couple of examples but I can't achieve to get the result I want. This is what I'm trying to get.

enter image description here

But impossible to know how can I place a title like "Please select a date" in the picture.

My code so far:

// OnTimeListener
val timeSetListener = TimePickerDialog.OnTimeSetListener { _, hourOfDay, minute ->
    calendar.set(Calendar.HOUR_OF_DAY, hourOfDay)
    calendar.set(Calendar.MINUTE,minute)
    updateTimeInView()
}

// Opening time picker dialog
val openingTimePickerDialog = TimePickerDialog(this,
   timeSetListener,
   calendar.get(Calendar.HOUR_OF_DAY),
   calendar.get(Calendar.MINUTE),true)
openingTimePickerDialog.setTitle("Opening Hours")
openingTimePickerDialog.show()

The updateTimeInView() function just change the TextView with the time selected in the picker.

Thanks for your help on this!


Solution

  • Try this code..

     openingTimePickerDialog.setMessage("Opening Hours")