更改日期选择器对话框主题

时间:2019-09-30 10:51:15

标签: android datepicker styles

我已经实现了datepickerdialog,并且想要删除“取消”和“确定”按钮的背景色,并更改这些按钮的文本颜色。这是在androidx项目中。

enter image description here

videos

样式-

public void displayCalendar(final TextView tv, final String myFormat) {
    DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {

        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear,
                              int dayOfMonth) {
            c.set(Calendar.YEAR, year);
            c.set(Calendar.MONTH, monthOfYear);
            c.set(Calendar.DAY_OF_MONTH, dayOfMonth);

            SimpleDateFormat sdf1 = new SimpleDateFormat(myFormat, Locale.US);
            str_date = sdf1.format(c.getTime());
            tv.setText(str_date);
            mListener.onDateSelected();
        }

    };
    DatePickerDialog datePickerDialog = new DatePickerDialog(con, R.style.DatePicker, date, c
            .get(Calendar.YEAR), c.get(Calendar.MONTH),
            c.get(Calendar.DAY_OF_MONTH));

    datePickerDialog.getDatePicker().setMinDate(System.currentTimeMillis() - 1000);
    datePickerDialog.setTitle("");
    datePickerDialog.show();
}

1 个答案:

答案 0 :(得分:0)

尝试如下

 Button btn_ok = alert.getButton(DialogInterface.BUTTON_POSITIVE);
 btn_ok .setBackgroundColor(Color.YELLOW); //add your color