TimePickerDialog in spinner mode
14,196
use this code show time picker as spinner
public void showCustomTimePicker()
{
final Calendar myCalender = Calendar.getInstance();
int hour = myCalender.get(Calendar.HOUR_OF_DAY);
int minute = myCalender.get(Calendar.MINUTE);
TimePickerDialog.OnTimeSetListener myTimeListener = new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
if (view.isShown()) {
myCalender.set(Calendar.HOUR_OF_DAY, hourOfDay);
myCalender.set(Calendar.MINUTE, minute);
}
}
};
TimePickerDialog timePickerDialog = new TimePickerDialog(getActivity(), android.R.style.Theme_Holo_Light_Dialog_NoActionBar, myTimeListener, hour, minute, true);
timePickerDialog.setTitle("Choose hour:");
timePickerDialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
timePickerDialog.show();
}
![Admin](/assets/logo_square_200-5d0d61d6853298bd2a4fe063103715b4daf2819fc21225efa21dfb93e61952ea.png)
Author by
Admin
Updated on June 09, 2022Comments
-
Admin about 2 years
In my project, I use
TimepickerDialog
to show the time in aTextView
. MyTimepickerdialog
is shown as a clock, but I want it shown as a spinner. How can I do this? -
Admin over 5 yearsThanks, but I have a timePickerDialog, not a timePicker
-
Rohit5k2 over 5 years@zahras: Use a theme that used spinner such as
android.R.style.Theme_Holo_Light_Dialog
-
Vadim Kotov almost 5 years
android.R.style.Theme_Holo_Light_Dialog
is deprecated in API 28. -
Vadim Kotov almost 5 years
android.R.style.Theme_Holo_Light_Dialog_NoActionBar
is deprecated in API 28. -
Jeremiah over 4 yearsIs there a non-deprecated theme that uses the spinner?