DatePickerDialog displays with two borders

2020-08-22 07:12发布

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?

1条回答
forever°为你锁心
2楼-- · 2020-08-22 07:38

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);
查看更多
登录 后发表回答