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以上這麼使用會崩潰。