DatePickerDialog显示带有两个边框 [英] DatePickerDialog displays with two borders

查看:166
本文介绍了DatePickerDialog显示带有两个边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对显示DatePickerDialog有一个疑问。



我想创建带有 HoloDialog主题的日期选择器对话框,如下所示:

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

然后我将看到以下结果:



如您所见,对话框显示为带有两个边框。 / p>

我想创建一个与此处显示的对话框相同的对话框,但是周围有一个边框。

解决方案

假设我正确理解了您的问题,我想我找到了一种方法。在这里,我们匿名地子类化 DatePickerDialog 来覆盖 onCreate()并为窗口设置透明背景。

  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));
}
};






您也可以使用自定义主题。例如:

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

然后在 DatePickerDialog 中传递构造函数:

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


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:

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?

解决方案

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);

这篇关于DatePickerDialog显示带有两个边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆