10

如何获得带有 Holo Light 主题的 DatePickerDialog?

创建时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);

or with theme android.R.style.Theme_Holo_Lightor android.R.style.Theme_Holo_Light_Dialog,我得到一个带有标准标题和标准按钮的日期选择器。我也尝试使用带有全息光父的自定义主题,但它也不起作用。它似乎适用于 theme android.R.style.Theme_Holo,但结果是深色背景(如预期的那样),但我想要一个浅色背景。

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

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

谢谢你的帮助。

4

3 回答 3

18

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

它对我有用。

于 2012-05-23T11:32:18.680 回答
3

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

这是这样一个

支持定义主题的 DatePickerDialog 构造函数。

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); 
于 2015-05-09T07:33:36.183 回答
3

对于 Material 风格,这对我有用:

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();
于 2016-11-18T08:27:53.067 回答