is24hourview = true,但是TimePickerDialog仍然向用户显示外部的12h时钟,这极大地干扰了我们的预期用户输入,因为我们希望将输入限制为24hr时钟。
try {
thisdate= new SimpleDateFormat("HH:mm", Locale.ENGLISH).parse(shiftstarttimetv.getText().toString());
thisdatecal.setTime(thisdate);
}catch(ParseException e){
}
new TimePickerDialog(this, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hour, int minute) {
SimpleDateFormat dateFormatfortime = new SimpleDateFormat("HH:mm");
date.set(Calendar.HOUR_OF_DAY,hour);
date.set(Calendar.MINUTE,minute);
shiftstarttimetv.setText(dateFormatfortime.format(date.getTime()));
updatebuttonbtn.setEnabled(true);
}
}, thisdatecal.get(Calendar.HOUR), thisdatecal.get(Calendar.MINUTE),true).show();
更新:修改主题解决了我们的问题!
TimePickerDialog tpd= new TimePickerDialog(LG_SINGLESHIFTVIEW.this,android.R.style.Theme_Holo_Light_Dialog_MinWidth, mOnTimeSetListener,thisdatecal.get(Calendar.HOUR_OF_DAY),thisdatecal.get(Calendar.MINUTE),true);
tpd.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
tpd.show();
mOnTimeSetListener = new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
SimpleDateFormat dateFormatfortime = new SimpleDateFormat("HH:mm");
date.set(Calendar.HOUR_OF_DAY,hourOfDay);
date.set(Calendar.MINUTE,minute);
shiftstarttimetv.setText(dateFormatfortime.format(date.getTime()));
updatebuttonbtn.setEnabled(true);
}
};
我想知道是否a)是否可以将TimePickerDialog小部件设置为仅显示24h选择b)是否可以创建TimePickerDialog小部件的副本并编辑其持久性以显示12h选择在外部,并且c)还有其他合理的时钟对话框小部件,可以以类似的方式来使用吗?