如何自定义首选项以通过 XML 显示时间选择器小部件

发布于 2024-10-18 02:36:11 字数 885 浏览 6 评论 0原文

首先我想说的是,我现在只在 Android 上工作了大约一周,所以我想你可以认为我是一个新手!因此,如果解决方案过于简单,我提前道歉,但我可以向您保证,我在发布到这里之前已经完成了研究,并且到目前为止还没有找到合适的解决方案(或者也许我已经但没有完全意识到这一点) !)。尽管如此,还是有很多乐趣,只是想解决这个问题并学习,所以这里...

应用程序

我正在开发的应用程序本质上是一个提醒服务,我目前正在开发<强>首选项屏幕。

问题

我希望用户能够指定每天提醒他/她的时间。我希望通过首选项屏幕完成此选择。这是我的首选项屏幕到目前为止的样子...

我的首选项屏幕

我的问题

理想情况下,每当用户选择“闹钟时间”首选项时,我希望出现以下内容(这是来自另一个应用程序 - PillReminder 的首选项的屏幕截图)。

时间选择器小部件的偏好(取自另一个应用程序 - “PillReminder”)

我的问题是,创建这个的最佳方法是什么?我确实希望仅使用 XML 保留应用程序的所有视觉方面,因此我不需要 Java 解决方案。这是可能的还是我完全偏离了轨道?我听说过的其他潜在解决方案是使用主题、警报对话框和扩展首选项类等。也许其中一些是正确的,但我不确定。

任何帮助将不胜感激,谢谢! :)

Firstly I'd like to say that I have only been working on Android for about a week now, so I guess you can consider me a newb! Therefore I apologise in advance if the solution is overly simple, but I can assure you that I have done my research before posting here, and haven't found an appropriate solution as of yet (or maybe I have and don't fully realise it!). Nonetheless, having lots of fun and just want to solve this problem and learn, so here goes...

The Application

The application I am developing is essentially a reminder service, and I am currently working on the preferences screen.

The Problem

I would like the user to be able to specifiy a time when he/she will be reminded daily. I want this selection to be done via the preferences screen. This is how my preferences screen looks so far...

My preferences screen

My Question

Ideally, whenever the user selects the "Alarm Time" preference, I would like the following to appear (this is a screenshot of a preference from another application - PillReminder).

Preference with Time Picker widget (taken from another app - "PillReminder")

My question is, what is the best way to create this? I really want to keep all the visual aspects of the application using only XML, therefore I don't want a Java solution. Is this possible or am I completely off track? Other potential solutions I have heard of are using themes, alert dialogs and extending preference classes etc. Maybe some of these are correct, but I am unsure.

Any help would be greatly appreciated, thanks! :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

段念尘 2024-10-25 02:36:11

我的问题是,创建这个的最佳方法是什么?

这可能是一个自定义的 DialogPreference,其中恰好有一个 TimePicker

我真的希望仅使用 XML 来保留应用程序的所有视觉方面,因此我不需要 Java 解决方案。

像这样的自定义首选项无法在 XML 中定义。您需要创建 DialogPreference 的子类,定义对话框中的内容,以及如何将对话框的内容存储到 SharedPreference 值(以及从中检索)。

我的 ColorMixer CWAC 项目 有一个 ColorPreference,您可能希望检查一下。

My question is, what is the best way to create this?

That is probably a custom DialogPreference that happens to have a TimePicker in it.

I really want to keep all the visual aspects of the application using only XML, therefore I don't want a Java solution.

Custom preferences like this cannot be defined in XML. You will need to create a subclass of DialogPreference, define what goes in the dialog, and how the dialog's contents can be stored to (and retrieved from) a SharedPreference value.

My ColorMixer CWAC project has a ColorPreference that you may wish to examine.

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