我正在尝试显示一个DatePicker
另一个活动之上的对话框,正在发生的事情是它以某种方式继承了它的颜色。
I'd like it to have a green header and white background,
这是样式的摘录
<style name="DatePickerDialog" parent="@android:style/Theme.Holo.Light">
<item name="android:windowFrame">@null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="colorAccent">@color/primary</item>
</style>
这段代码用于弹出DatePicker
DatePickerDialog datepicker = new DatePickerDialog(this, R.style.DatePickerDialog, new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
TextView newdate = (TextView) findViewById(R.id.newdate);
Date date = getDate(year, monthOfYear, dayOfMonth);
DateFormat dateformat = new SimpleDateFormat(getResources().getString(R.string.date_format_full));
newdate.setText(dateformat.format(date));
}
}, newCalendar.get(Calendar.YEAR), newCalendar.get(Calendar.MONTH), newCalendar.get(Calendar.DAY_OF_MONTH));
datepicker.show();
If I specify the white background in the styles,
<item name="android:background">@color/app_background</item>
我尝试的最后一件事是使用AlertDialog.THEME_DEVICE_DEFAULT_DARK
as the DatePicker
theme
DatePickerDialog datepicker = new DatePickerDialog(this,
AlertDialog.THEME_DEVICE_DEFAULT_DARK, new
DatePickerDialog.OnDateSetListener()
这是我打开对话框的活动的样式
<style name="UserDialog" parent="android:style/Theme.Dialog">
<item name="android:windowFrame">@null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:background">@color/primary</item>
<item name="android:textColor">@color/dialog_text</item>
<item name="colorPrimary">@color/app_background</item>
<item name="android:windowTitleStyle">@style/NewDialogTitle</item>
</style>
<style name="NewDialogTitle" parent="@android:style/TextAppearance.DialogWindowTitle">
<item name="android:gravity">center_horizontal</item>
</style>
以及我正在使用的颜色
<color name="primary">#4CAF50</color>
<color name="app_background">#FFFFFF</color>
有谁知道如何完成它?我将不胜感激任何指导。我尝试跟随这个答案,但没有运气 https://stackoverflow.com/questions/28738089/change-datepicker-dialog-color-for-android-5-0