pranatayudha
pranatayudha

Reputation: 27

Change input mode for TimePickerDialog

I saw from the documentation, there explained that we could change the input mode, for example the script:

builder.setInputMode (MaterialDatePicker.INPUT_MODE_TEXT);

So, how can I change the input mode using the TimePickerDialog class?

Basically I want to make the default as shown below:

I use fragments when calling TimePickerDialog, like this:

@SuppressLint("DefaultLocale") TimePickerDialog timePickerDialog = new TimePickerDialog(getContext(),
                (view13, hourOfDay, minute1) -> {
                    String time = String.format("%02d:%02d", hourOfDay, minute1);
                    viewModel.setTimeIn(time);
                },
                Integer.parseInt(hour), Integer.parseInt(minute), false);
        timePickerDialog.show();

Upvotes: 1

Views: 1351

Answers (1)

Gabriele Mariotti
Gabriele Mariotti

Reputation: 364858

It is related to the new MaterialTimePicker included in the Material Components Library.

val materialTimePicker = MaterialTimePicker.Builder()
    .setInputMode(MaterialTimePicker.INPUT_MODE_KEYBOARD)
    .build()

materialTimePicker.show(supportFragmentManager, "fragment_tag")

enter image description here

Note: this code requires at least the version 1.3.0-alpha03.

Upvotes: 1

Related Questions