为什么TimePicker对话在三星Marshmallow 6.0.1上是空白的?

时间:2016-07-29 16:46:48

标签: android android-6.0-marshmallow android-timepicker

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

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

完全空白。

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();

1 个答案:

答案 0 :(得分:4)

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

cirit 提供的解决方案是将TimePicker小部件放入AlertDialog。我对他/她的解决方案的实现如下:

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();
}

不漂亮,但它有效(对我而言)并不像我担心的那样难看。