-1

I've got a DatePickerDialog of which I would like to change the background color of the header. I've made it so that the default background of the whole application is white but now, because of the white text in the header of the Dialog it's not visible and looks very weird. enter image description here

I've tried to use many other answers from SO but no luck there, this is the style I have set up in my styles.xml

<style name="DialogTheme" parent="Theme.AppCompat.Light.Dialog">
    <item name="android:textSize">12dp</item>
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorPrimary</item>
    <item name="android:headerBackground">@color/colorPrimary</item>
</style>

Much appreciated!

Edit: For now, since I don't use many layouts in this app, I've fixed it by setting the background for each element to white manually. A fix would still be nice...

Rodin10
  • 327
  • 3
  • 15

2 Answers2

0
//Put it inside style.xml file
<style name="yourCustomStyle" parent="Theme.AppCompat.Light">
        <item name="colorAccent">@color/blue</item>
        <item name="android:textColorPrimaryInverse">@color/yellow</item>
        .. other
    </style>

//After replace below code to your code 

new DatePickerDialog(MainActivity.this, R.style.yourCustomStyle, new DatePickerDialog.OnDateSetListener() {
    @Override
    public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) 
    {

    }
}, 2015, 02, 26).show();
0
//Put it in your style.xml file
 <style name="datepicker" parent="Theme.AppCompat.Light.Dialog">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorPrimary</item>
        <item name="android:fontFamily">@font/quicksand_regular</item>
    </style>


//after below code put in your view  onclickListner 

public void Datepiker()
{
    // Get Current Date
    final Calendar c = Calendar.getInstance();
    mYear = c.get(Calendar.YEAR);
    mMonth = c.get(Calendar.MONTH);
    mDay = c.get(Calendar.DAY_OF_MONTH);
    DatePickerDialog datePickerDialog = new DatePickerDialog(this,R.style.datepicker,
            new DatePickerDialog.OnDateSetListener() {

                @Override
                public void onDateSet(DatePicker view, int year,
                                      int monthOfYear, int dayOfMonth) {

                    txt_PickupDate_val.setText(dayOfMonth + "-" + monthOfYear  + "-" + year);

                  //  txt_PickupDate_val.setEnabled(true);
                }
            }, mYear, mMonth, mDay);
    datePickerDialog.show();
}