为什么 TimePicker 对话框在 Samsung Marshmallow 6.0.1 上是空白的?

Why Is TimePicker Dialog Blank On Samsung Marshmallow 6.0.1?

在 Nexus 4 上的 Lollipop 5.1.1 和模拟器上的 Marshmallow 6.0.1 上,TimePickerDialog 出现在我的应用程序中,如下所示:

然而,在 Samsung S6 Edge 运行 Marshmallow 6.0.1 上,它出现如下:

完全空白。

TimePickerDialog 初始化如下:

Calendar calendar = Calendar.getInstance();
Dialog timeDialog = new TimePickerDialog(androidContext, this, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), true);
timeDialog.setTitle("Set Appointment Time");
timeDialog.show();

我不知道为什么会这样,但我已经使用 cirit here 提供的解决方案解决了这个问题。他正在解决一个不同的问题,但它也解决了这个问题。

cirit提供的解决方案是将TimePicker widget放入AlertDialog中。我的 his/her 解决方案的实现如下所示:

private void showTimePicker() {

    // This is implemented using an AlertDialog and a TimePicker instead of a TimePickerDialog
    // because the TimePickerDialog implementation on Samsung does not work.
    final Calendar c = Calendar.getInstance();
    c.setTimeInMillis(getInternalTimestamp());

    final TimePicker timePicker = new TimePicker(mContext);
    timePicker.setIs24HourView(DateFormat.is24HourFormat(mContext));
    timePicker.setCurrentHour(c.get(Calendar.HOUR_OF_DAY));
    timePicker.setCurrentMinute(c.get(Calendar.MINUTE));

    final AlertDialog timePickerDialog = new AlertDialog.Builder(mContext)
            .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // user clicked OK - store the result, perhaps by using a callback:
                    // myCallback.onTimeSet(timePicker, timePicker.getHour(), timePicker.getMinute();
                }
            })
            .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            })
            .setView(timePicker).show();
}

不漂亮,但(对我来说)很管用,也没有我担心的那么难看。