android DatePickerDialog只显示一个按钮 [英] android DatePickerDialog display only one button

查看:266
本文介绍了android DatePickerDialog只显示一个按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 DatePickerDialog 存在很多问题,如这篇帖子中所述果冻豆DatePickerDialog ---是否可以取消?但我的问题是我只想 显示确认按钮,而不是两个按钮。我在 DialogFragment 中使用 DatePickerDialog ,像这样:

I know there are a lot of problems with DatePickerDialog as explain at this post Jelly Bean DatePickerDialog --- is there a way to cancel? but my problem is that I want to only display the confirmation button instead of two buttons. I use a DatePickerDialog in DialogFragment like this:

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);
}
}


推荐答案

I终于找到了更简单的解决方案。这是我的 CustomDatePickerDialog 中的工作原理,它扩展了 DatePickerDialog

I've finally found an easier solution. Here is the workaraound in my CustomDatePickerDialog which extends 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只显示一个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆