De-Great Yartey
De-Great Yartey

Reputation: 1654

TimePicker Clock mode below Lollipop

I am trying to make my TimePicker appear as a clock. I use timepickermode="clock" but I get a lint warning that says that it's compatible with api level 21 and above.

I've seen this feature ran on my kitkat in Todoist app. How else do I implement this?

Upvotes: 0

Views: 5051

Answers (2)

Amir
Amir

Reputation: 16607

Here is good library which brings some Material widget to Pre-lolipop devices , You can find time-picker too.

Upvotes: 0

Mattia Maestrini
Mattia Maestrini

Reputation: 32810

You can't use the TimePicker with clock look in version prior Lollipop as stated by the documentation:

timePickerMode
Defines the look of the widget. Prior to the L release, the only choice was spinner. As of L, with the Material theme selected, the default layout is clock, but this attribute can be used to force spinner to be used instead.

There is an alternative offered by Google itself. It is an external datepicker project that is compatible with API level 14 and higher. You can find the project here:

https://android.googlesource.com/platform/frameworks/opt/datetimepicker/

Once you clone the repo, add it to your existing project, then you can use the TimePicker like this:

TimePickerDialog timePickerDialog = new TimePickerDialog();
timePickerDialog.setOnTimeSetListener(new TimePickerDialog.OnTimeSetListener() {
    @Override
    public void onTimeSet(RadialPickerLayout view, int hourOfDay, int minute) {

    }
});
timePickerDialog.show(getFragmentManager(), fragmentTag);

Be careful to import the com.android.datetimepicker.time.TimePickerDialog not the standard android.app.TimePickerDialog.

Upvotes: 2

Related Questions