代码之家  ›  专栏  ›  技术社区  ›  user8371791

在datePickerDialog中,如何用清除按钮替换取消按钮?

  •  0
  • user8371791  · 技术社区  · 8 年前

    由a 清除按钮 ? 当我们点击它的时候就可以捕捉到事件?

    enter image description here

    2 回复  |  直到 8 年前
        1
  •  0
  •   Angel Kjoseski    8 年前

    这应该可以解决您的需求:

        DatePickerDialog datePickerDialog = new DatePickerDialog(
                this, null, 2000, 1, 1);
        datePickerDialog.setButton(android.content.DialogInterface.BUTTON_NEGATIVE,
                getString(R.string.your_text), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // todo on click
                    }
                });
        datePickerDialog.show();
    
        2
  •  0
  •   anomeric    8 年前

    new DatePickerDialog.Builder(this).setNegativeButton("Clear", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            // they hit the clear button
        }
    });