我知道 DatePickerDialog
有很多问题,正如这篇文章 Jelly Bean DatePickerDialog --- is there a way to cancel? 所解释的那样,但我的问题是我只想显示确认按钮而不是两个按钮。我在 DatePickerDialog
中使用了 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
中的 workaraound,它扩展了 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
}
关于android DatePickerDialog只显示一个按钮,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18355524/