主题为Holo Light的DatePickerDialog?

时间:2012-02-14 14:39:41

标签: android android-widget android-theme

如何使用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);

或使用主题android.R.style.Theme_Holo_Lightandroid.R.style.Theme_Holo_Light_Dialog,我会得到一个带有标准标题和标准按钮的日期选择器。我也尝试使用自定义主题和holo light父级,但它也不起作用。它似乎与主题android.R.style.Theme_Holo一起使用,但结果是一个黑暗的背景(如预期的那样),但我希望有一个轻松的背景。

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

我在这里看到了一个示例:http://as400samplecode.blogspot.com/2011/10/android-datepickerdialog.html,它显示了一个带有全息灯主题的DatePickerDialog,就像我希望拥有它一样。我不知道为什么它不适用于我的设置。

感谢您的帮助。

2 个答案:

答案 0 :(得分:17)

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

这样对我有用。

答案 1 :(得分:2)

对于材质风格,这对我有用:

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();
相关问题