2

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!

schtipoun
  • 423
  • 3
  • 9

1 Answers1

8

Try this code..

 openingTimePickerDialog.setMessage("Opening Hours")
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
  • 1
    Well played! I could swear I went through all the different possibilities without finding something else than title but apparently, I've missed that one! Thanks for your quick help :-) – schtipoun May 16 '19 at 14:10