I have the following date picker
DatePickerDialog dialog = new DatePickerDialog(
ctx,
R.style.DatePicker,
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
.....dostuff
}
},
year, month, day);
dialog.show();
In my styles i have setup
<style name="DatePicker" parent="Theme.AppCompat.Light.Dialog">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/primary</item>
</style>
And my colors
<color name="colorPrimary">#3fb55b</color>
<color name="colorPrimaryDark">#FF247038</color>
<color name="colorAccent">#ece9ea</color>
<color name="colorBackground">#238927</color>
But whenever i show the datepicker it always shows a white background as in the following screenshot
What else do i need to add for the green background to show
答案 0 :(得分:0)
Add this lines to your style.xml file
<style name="DialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:background">#000 <!--add you backgroud color here --> </item>
</style>
Then :
DatePickerDialog dialog = new DatePickerDialog(
ctx,
R.style.DialogTheme,
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
.....dostuff
}
},
year, month, day);
dialog.show();
Hope this helps
答案 1 :(得分:-1)
您使用下面的代码更改datepickerdialog背景:
<style name="datePicker">
<item name="android:background">@color/custColtransparante</item>
</style>
然后用于将样式设置为datepicker:
private void showDatePicker() {
Calendar cal = Calendar.getInstance();
int day = cal.get(Calendar.DAY_OF_MONTH);
int month = cal.get(Calendar.MONTH);
int year = cal.get(Calendar.YEAR);
DatePickerDialog datePicker = new DatePickerDialog(this, R.style.Snackbar,new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int mYear, int mMonth, int mDayOfMonth) {
Log.d("Rail", "Year-" + mYear);
Log.d("Rail", "Month-" + mMonth);
Log.d("Rail", "Day-" + mDayOfMonth);
String dateto = "" + mDayOfMonth + "/" + mMonth + "/" + mYear;
textView.setText(dateto);
}
}, year, month, day);
datePicker.show();
}