我知道有很多问题DatePickerDialog
正如这篇文章所解释的Jelly Bean DatePickerDialog --- 有办法取消吗? https://stackoverflow.com/questions/11444238/jelly-bean-datepickerdialog-is-there-a-way-to-cancel但我的问题是我想要only显示确认按钮而不是两个按钮。我用一个DatePickerDialog
in DialogFragment
像这样:
public class DateDialog extends DialogFragment implements DatePickerDialog.OnDateSetListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
// set up mindate
minYear = year;
minMonth = month;
minDay = day;
// Create a new custom instance of DatePickerDialog and return it
return new CustomDatePickerDialog(getActivity(), this, year, month, day);
}
}
我终于找到了一个更简单的解决方案。这是我的解决方法CustomDatePickerDialog
这延伸了DatePickerDialog
public CustomDatePickerDialog(Context context, OnDateSetListener callBack, int year, int monthOfYear,int dayOfMonth) {
super(context, callBack, year, monthOfYear, dayOfMonth);
this.setButton(DatePickerDialog.BUTTON_POSITIVE, "OK",this);
this.setButton(DatePickerDialog.BUTTON_NEGATIVE, "",this); // hide cancel button
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)