2012-02-14 73 views
9

如何获得Holo Light主题的DatePickerDialog?DatePickerDialog与主题Holo Light?

当创建一个DatePickerDialog如下:

DatePickerDialog dpd = new DatePickerDialog(new ContextThemeWrapper(this, 
        android.R.style.Theme_Holo_Light_Dialog_NoActionBar), 
    new DateListener(v), mTime.year, mTime.month, mTime.monthDay); 

或主题android.R.style.Theme_Holo_Lightandroid.R.style.Theme_Holo_Light_Dialog,我得到一个标准的标题和标准按钮的日期选择器。我也尝试使用全息照明父母的自定义主题,但它也不起作用。它似乎与主题android.R.style.Theme_Holo,但结果是一个黑暗的背景(如预期),但我想有一个轻。

应用程序的android.jar版本为14,该应用程序在android版本3.2的设备上运行。

我在这里看到一个例子:http://as400samplecode.blogspot.com/2011/10/android-datepickerdialog.html,它显示了一个DatePickerDialog与全光主题,我想要的方式。我不知道为什么它不适用于我的设置。

谢谢你的帮助。

+0

放机器人:主题= “@安卓风格/ Theme.Holo.Light” 在您的活动标签中的manifest.xml – 2012-02-14 14:45:22

+0

@PadmaKumar谢谢你的评论。我会尝试你的建议。但一般来说,我想使用父主题android:Theme.Holo.Light.DialogWhenLarge为主题。 – Julia 2012-02-14 14:50:01

+0

@PadmaKumar我把android:theme =“@ android:style/Theme.Holo.Light”放在manifest.xml的activity标记中,它没有改变任何东西(我想,因为我使用了'ContextThemeWrapper')。 – Julia 2012-02-14 14:56:40

回答

16

DatePickerDialog有它接受一个主题

DatePickerDialog(Context context, int theme, DatePickerDialog.OnDateSetListener callBack, int year, int monthOfYear, int dayOfMonth) 

只需更新你的代码,包括无需你想要的样式为ContextThemeWrapper

DatePickerDialog dpd = new DatePickerDialog(this, 
       android.R.style.Theme_Holo_Light_Dialog_NoActionBar, 
new DateListener(v), mTime.year, mTime.month, mTime.monthDay); 

它的工作对我来说这样的构造函数。

+0

android.R.style.Theme_Holo_Light_Dialog_NoActionBar是否可用于版本<2.0? – 2013-04-11 07:11:28

+0

@ Yume117:没有霍洛主题被添加到蜂窝3.0 – SuperShalabi 2013-06-16 12:16:46

2

阅读此Android DatePickerDialog示例代码其中包括如何使用不同主题DatePickerDialog

这是such one

DatePickerDialog支持定义Theme的构造函数。

final Calendar c = Calendar.getInstance(); 
    int year = c.get(Calendar.YEAR); 
    int month = c.get(Calendar.MONTH); 
    int day = c.get(Calendar.DAY_OF_MONTH); 
return new DatePickerDialog(getActivity(), AlertDialog.THEME_HOLO_DARK, this, year, month, day); 
+0

虽然这个答案可能是正确的,但最好添加一些解释。如果提供的链接变得无效,那么现在的答案将不再适用。 – Wouter 2015-05-09 07:56:59

1

对物质的风格这个工作对我来说:

int datePickerThemeResId = 0; 
if (android.os.Build.VERSION.SDK_INT >= 21) { 
    datePickerThemeResId = android.R.style.Theme_Material_Light_Dialog; 
} 
new DatePickerDialog(
    context, 
    datePickerThemeResId, 
    (view, year, month, dayOfMonth) -> {}, 
    year, 
    month, 
    day 
).show(); 
相关问题