android - 更改日期选择器对话框主题
问题描述
我已经实现了 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
推荐阅读
- excel - 在 Excel 中,如何返回与描述匹配的值列表?
- excel - 无法使用 spark-excel 库读取 .xlsx 文件
- python-2.7 - 在scrapy中提取标签值
- c# - 在测试完成中参数化 Connect.Sys 属性
- javascript - Angular 7:mat-select 无法在 ReactiveForm 中设置没有 ngModel 的默认选项
- sql-server - 运行 SP 时的选择标准
- angular - angular 6 profile card onhover
- asp.net-core - ASP.NET Core EF 未找到导航属性
- c# - 为什么文件没有通过 tcp 在 C# 中的客户端和 C 中的服务器之间正确传输(保存?)?
- excel - 在 VBA 中的字典值中查找最大值/最小值