我已经实现了 datepickerdialog 并且想要删除 Cancel 和 Ok Button 的背景颜色并更改这些按钮的文本颜色。这是在androidx项目中。
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();
}
在风格上——
<style name="DatePicker" parent="Theme.MaterialComponents.Light.Dialog">
<item name="colorPrimary">#377dff</item>
<item name="colorPrimaryDark">#1C5CD3</item>
<item name="colorAccent">#377dff</item>
</style>
尝试如下
Button btn_ok = alert.getButton(DialogInterface.BUTTON_POSITIVE);
btn_ok .setBackgroundColor(Color.YELLOW); //add your color
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句