答案 0 :(得分:2)
您可以使用以下lib:https://github.com/lutvie72/RackMonthPicker。
new RackMonthPicker(this)
.setPositiveButton(new DateMonthDialogListener() {
@Override
public void onDateMonth(int month, int startDate, int endDate, int year, String monthLabel) {
}
})
.setNegativeButton(new OnCancelMonthDialogListener() {
@Override
public void onCancel(AlertDialog dialog) {
}
}).show();
答案 1 :(得分:0)
最简单的方法,也许不是最纯粹的方法是扩展DatePickerDialog
您需要它来覆盖onYearSelected
回调,然后newInstance
,因为如果您不这样做,它将产生DatePickerDialog
,而不是新的YearOnlyPicker
对象。另外newInstance
我添加了showYearPickerFirst(true)
来电,但也可以从外面完成。然后您可以将此对话框用作原始对话框。这是一种破解,但它是在不修改库源代码的情况下实现这一目标的唯一方法
这是扩展DatePickerDialog
的类 import com.wdullaer.materialdatetimepicker.date.DatePickerDialog;
public class YearOnlyPicker extends DatePickerDialog {
public static YearOnlyPicker newInstance(OnDateSetListener callBack, int year,
int monthOfYear,
int dayOfMonth) {
YearOnlyPicker ret = new YearOnlyPicker();
ret.showYearPickerFirst(true);
ret.initialize(callBack, year, monthOfYear, dayOfMonth);
return ret;
}
@Override
public void onYearSelected(int year) {
super.onYearSelected(year);
notifyOnDateListener();
dismiss();
}
}