TimePickerDialog的使用
TimePicker有两种模式:spinner 和clock,可通过如下方式配置:
<TimePicker android:id="@+id/timePicker" android:layout_width="match_parent" android:layout_height="wrap_content" android:timePickerMode="spinner" android:layout_gravity="center_horizontal" />
或:
android:timePickerMode = "clock"
设置显示的小时样式:
timePicker = (TimePicker) findViewById(R.id.timePicker); timePicker.setIs24HourView(true);
另外关于TimePickerDialog的样式。TimePickerDialog可以配置很多种样式,可以直接在构造函数中来配置。代码如下:
private void showTimeDialog( final int view){ new TimePickerDialog(this, AlertDialog.THEME_HOLO_LIGHT, new TimePickerDialog.OnTimeSetListener() { @Override public void onTimeSet(TimePicker timePicker, int hourOfDay, int minute) { switch (view) { case R.id.tv_begin: begin=String.format(Locale.getDefault(),"%02d:%02d",hourOfDay,minute); tvBegin.setText(begin); break; case R.id.tv_end: end=String.format(Locale.getDefault(),"%02d:%02d",hourOfDay,minute); tvEnd.setText(end); break; } } }, calendar.get(Calendar.HOUR_OF_DAY),calendar.get(Calendar.MINUTE),true).show(); }
AlertDialog.THEME_HOLO_LIGHT是给dialog设置样式。