package com.example.longdemo;
import android.app.DatePickerDialog;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.DatePicker;
public class MyDatePickerDialogWithoutDay extends DatePickerDialog {
public MyDatePickerDialogWithoutDay(Context context,
OnDateSetListener callBack, intyear, int monthOfYear,
int dayOfMonth) {
super(context, callBack, year, monthOfYear, dayOfMonth);
//设置title,不用系统的title
this.setTitle(year + "年" + (monthOfYear + 1) + "月");
//去掉日数据
((ViewGroup) ((ViewGroup) this.getDatePicker().getChildAt(0))
.getChildAt(0)).getChildAt(2).setVisibility(View.GONE);
}
@Override
publicvoid onDateChanged(DatePicker view, intyear, intmonth, intday) {
super.onDateChanged(view, year, month, day);
//重新设置title
this.setTitle(year + "年" + (month + 1) + "月");
}
}
使用方法:与普通的DatePickerDialog一样。
注意:7.0以上这么使用会崩溃。