AndroidDatePickerDialog和TimePickerDialog显⽰样式可以⽤DatePickerDialog显⽰选取⽇期的对话框。可以设置显⽰的样式
1、通过构造⽅法设置显⽰样式。
可以通过DatePickerDialog(Context context, int theme, DatePickerDialog.OnDateSetListener callBack, int year, int monthOfYear, int dayOfMonth)这个构造⽅法的第⼆个参数来设置显⽰样式。
这个theme参数对应的值,可以使⽤AlertDialog中的theme值。
AlertDialog.THEME_TRADITIONAL
AlertDialog.THEME_HOLO_DARK
AlertDialog.THEME_HOLO_LIGHT
AlertDialog.THEME_DEVICE_DEFAULT_DARK
AlertDialog.THEME_DEVICE_DEFAULT_LIGHT
2、通过DatePicker设置显⽰样式
⾸先获取DatePicker,然后使⽤DatePicker.setCalendarViewShow(boolean)和DatePicker.setSpinnersShow(boolean)来设置。
CalendarView和Spinners的值分别为true和false
CalendarView和Spinners的值分别为false和true
CalendarView和Spinners的值都是false
CalendarView和Spinners的值都是true
对于TimePickerDialog⽽⾔,它的样式设置,只有构造函数⼀种⽅式,对应的theme参数和DatePickerDialog相同。它内部定义了⼀个TimePicker,但是没有提供获取的⽅式。
在构造TimePickerDialog和DatePickerDialog的时候最好使⽤DialogFragment来进⾏构造。
帮助⽂档中例⼦:
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 = Instance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
// Create a new instance of TimePickerDialog and return it
return new TimePickerDialog(getActivity(), this, hour, minute,
alertdialog使用方法DateFormat.is24HourFormat(getActivity()));
}
public void onTimeSet(TimePicker view, int hourOfDay, int minute) { // Do something with the time chosen by the user
}
}
public void showTimePickerDialog(View v) {
DialogFragment newFragment = new TimePickerFragment();
newFragment.show(getSupportFragmentManager(), "timePicker"); }
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论