DatePickerDialog 是个日期控件,在使用此控件的时候发现啊每当选择日期的时候,dialog的标题也会随之改变,还会显示星期,一行基本放不下,所以打算去掉这个效果,但是貌似没有这样的接口来实现。下面看看此控件的源码是如何实现的: DatePickerDialog实现了OnDateChangedListener,在OnDateChangedListener中会调用updateTitle(year, month, day); 所以会dialog的标题会变化看看部分源码
- public class DatePickerDialog extends AlertDialog implements OnClickListener,
- OnDateChangedListener {
- public void onDateChanged(DatePicker view, int year,
- int month, int day) {
- updateTitle(year, month, day);
- }
- private void updateTitle(int year, int month, int day) {
mCalendar.set(Calendar.YEAR, year);
mCalendar.set(Calendar.MONTH, month);
mCalendar.set(Calendar.DAY_OF_MONTH, day);
setTitle(mTitleDateFormat.format(mCalendar.getTime()));
}
- }
根据这个代码,要实现去掉标题的效果,可以自己实现OnDateChangedListener,即可
- public class SetTitleDatePickerDialog extends DatePickerDialog implements
- OnDateChangedListener {
- public SetTitleDatePickerDialog(Context context, int theme,
- OnDateSetListener callBack, int year, int monthOfYear,
- int dayOfMonth) {
- super(context, theme, callBack, year, monthOfYear, dayOfMonth);
- // TODO Auto-generated constructor stub
- }
- public SetTitleDatePickerDialog(Context context, OnDateSetListener callBack,
- int year, int monthOfYear, int dayOfMonth) {
- this(context, com.android.internal.R.style.Theme_Dialog_Alert,
- callBack, year, monthOfYear, dayOfMonth);
- }
- public void onDateChanged(DatePicker view, int year, int month, int day) {
- // updateTitle(year, month, day);
- }
- }
阅读(2662) | 评论(0) | 转发(0) |