无法将安卓时间选择器模式 24 小时模式更改为AM_PM模式



我在这里使用时间选择器拨号,但由于某种我不明白的原因,我无法将time picker的模式更改为AM_PM mode我已经尝试了代码timepicker.setIs24HourView(false);这是我的代码

onCreate(..){
button.onClickListe..(new...(){
showTimePickerDialog();
});}

 public static class TimePickerFragment extends DialogFragment implements
        TimePickerDialog.OnTimeSetListener {
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        // Use the current time as the default values for the picker
        final Calendar c = Calendar.getInstance();
        int hour = c.get(Calendar.HOUR_OF_DAY);
        int minute = c.get(Calendar.MINUTE);
        // Create a new instance of TimePickerDialog and return
        return new TimePickerDialog(getActivity(), this, hour, minute,
                true);
    }
    public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
       view.setIs24HourView(false);//TODO not working <-------- This code is not working here
        setTimeString(hourOfDay, minute, 0);
        timeView.setText(timeString);
    }
}

`private void showTimePickerDialog() {
    DialogFragment newFragment = new TimePickerFragment();
    newFragment.show(getFragmentManager(), "timePicker");
}`}
检查构造

函数TimePickerDialog中的最后一个参数,该参数为 24 小时格式,因此禁用 24 小时格式并传递最后一个参数false值:

return new TimePickerDialog(getActivity(), this, hour, minute,false);

最新更新