1

I Need to show keyboard entry by default to select time. While showing time picker dialog in circular style, it has keyboard icon to change circular style to manual entry style. This feature is available from Android Oreo OS devices. How to show Time picker dialog with manual(keyboard) entry by default in supporting devices ?

Any help with this will be appreciated. I know question is already here. Someone asked this before.

Here is my time picker dialog code

        var startHour = 0
    var startMinute = 0

    val c = Calendar.getInstance()
    startHour = c.get(Calendar.HOUR_OF_DAY)
    startMinute = c.get(Calendar.MINUTE)


    val timepickerdialog =
        TimePickerDialog(
            this,
            R.style.DialogThemeTimePicker,
            TimePickerDialog.OnTimeSetListener { _, hour, minute ->
                val pickedDateTime = Calendar.getInstance()
                val simpleDateFormat = SimpleDateFormat(DATE_TIME_FORMAT)


                val simpleDateFormat2 = SimpleDateFormat(TIME_FORMAT)
                simpleDateFormat.format(pickedDateTime.getTime())

                val newTime = Calendar.getInstance()

                newTime[Calendar.HOUR_OF_DAY] = hour
                newTime[Calendar.MINUTE] = minute


                var formattedtime=simpleDateFormat2.format(newTime.getTime()).toUpperCase()

                filterPostTimeVal = formattedtime    


            },
            startHour,
            startMinute,
            false
        )
    timepickerdialog.show()

And here is the theme used

    <style name="DialogThemeTimePicker" parent="Theme.AppCompat.Light.Dialog">
    <item name="colorAccent">@color/ColorGreen</item>
</style>
SARATH V
  • 500
  • 1
  • 7
  • 33

1 Answers1

0

The time picker can be started in text input mode with:

MaterialTimePicker.Builder().setInputMode(INPUT_MODE_KEYBOARD)

For example:

val now = LocalDateTime.now()
val hour = now.hour
val minute = now.minute

val picker =
    MaterialTimePicker.Builder()
        .setTimeFormat(TimeFormat.CLOCK_12H)
        .setHour(hour)
        .setMinute(minute)
        .setInputMode(MaterialTimePicker.INPUT_MODE_KEYBOARD)
        .setTheme(R.style.DialogThemeTimePicker)
        .build()

picker.addOnPositiveButtonClickListener {
    val pickedHour = picker.hour
    val pickedMinute = picker.minute
}

picker.show(supportFragmentManager, "TimePicker")

Source: https://material.io/components/time-pickers/android#using-time-pickers

biinui
  • 73
  • 2
  • 6