How to set TimePicker show with format 24h

前端 未结 11 1020
独厮守ぢ
独厮守ぢ 2020-12-29 18:17

I\'ve created a TimePicker in layout and I want it to show time with format 24h.

Can you help me? Thanks.

11条回答
  •  余生分开走
    2020-12-29 18:47

    I need the same just for an application to set the duration spend for doing a task. I found that I just need to extend the TimePickerDialog class and pass True in the last constructor parameter boolean is24HourView.

    public class DurationPickerDialog extends TimePickerDialog {
    
    public DurationPickerDialog(Context context, TimePickerDialog.OnTimeSetListener callBack, int hourOfDay, int minute){
        super(context, callBack, hourOfDay, minute, true);
    }
    

    Then you only need to create this as

    TimePickerDialog durationPicker =  new DurationPickerDialog(getActivity(), this, hour, minute);
    durationPicker.setTitle("Duration:");
    

提交回复
热议问题