DatePickerDialog 主题为 Holo Light?
如何获得具有 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_Light
或 android.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
,这是我想要的方式 它。我不知道为什么它不适合我的设置。
谢谢你的帮助。
How is it possible to get a DatePickerDialog with Holo Light theme?
When creating a DatePickerDialog
as follows:
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_Light
or android.R.style.Theme_Holo_Light_Dialog
, I get a date picker with a standard title and standard buttons. I tried to use a custom theme with a holo light parent too, but it didn't work either. It seems to work with theme android.R.style.Theme_Holo
, but the result is a dark background (as expected), but I would like to have a light one.
The application's android.jar is of version 14, the application is running on a divice with android version 3.2.
I have seen an example here: http://as400samplecode.blogspot.com/2011/10/android-datepickerdialog.html, which shows a DatePickerDialog
with the holo light theme, the way I would like to have it. I don't know why it doesn't work with my setup.
Thank you for help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(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);
对于 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();
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
DatePickerDialog
有一个构造函数,它接受一个主题,只需更新您的代码以包含您想要的样式,而不需要
ContextThemeWrapper
它对我来说就是这样。
The
DatePickerDialog
has a constructor which accepts a themejust update your code to include the style you want without the need for a
ContextThemeWrapper
It's working for me that way.