DatePickerDialog 主题为 Holo Light?

发布于 01-05 16:14 字数 928 浏览 3 评论 0原文

如何获得具有 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 时,我得到一个具有标准标题和标准按钮的日期选择器。我也尝试使用带有全息光父级的自定义主题,但它也不起作用。它似乎适用于主题 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

_蜘蛛2025-01-12 16:14:37

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

它对我来说就是这样。

The DatePickerDialog has a constructor which accepts a theme

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

just update your code to include the style you want without the need for a ContextThemeWrapper

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

It's working for me that way.

笑看君怀她人2025-01-12 16:14:37

阅读此 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); 

Read this Android DatePickerDialog example code which includes how to use different Themes in DatePickerDialog.

Here is the such one.

DatePickerDialog Constructor which support to define 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); 
神经大条2025-01-12 16:14:37

对于 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();

For Material style this worked for me:

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();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文