Search code examples
androidandroid-datepickerdatepickerdialog

DatePickerDialog displays with two borders


I have a question about DatePickerDialog displaying.

I want to create date picker dialog with "HoloDialog" theme like this:

DatePickerDialog dpd = new DatePickerDialog(this, android.R.style.Theme_Holo_Dialog, reservationDate, 2014, 1, 1);

Then I will see this result: DatePickerDialog with Holo_Dealog

As you can see, dialog is displayed with "two borders" around.

I want to create the same dialog as displayed here, but with one border around. Is it possible?


Solution

  • Assuming I understand your question correctly, I think I found a way. Here, we anonymously subclass DatePickerDialog to override onCreate() and set a transparent background for the window.

    DatePickerDialog dpd = new DatePickerDialog(this, android.R.style.Theme_Holo_Dialog,
                                                reservationDate, 2014, 1, 1) {
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        }
    };
    

    You could also do this with a custom theme instead. For example:

    <style name="HoloDialog" parent="@android:style/Theme.Holo.Dialog">
        <item name="android:windowBackground">@android:color/transparent</item>
    </style>
    

    Then pass that in the DatePickerDialog's constructor:

    DatePickerDialog dpd = new DatePickerDialog(this, R.style.HoloDialog,
                                                reservationDate, 2014, 1, 1);