如何自定义首选项以通过 XML 显示时间选择器小部件
首先我想说的是,我现在只在 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 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能是一个自定义的
DialogPreference
,其中恰好有一个TimePicker
。像这样的自定义首选项无法在 XML 中定义。您需要创建
DialogPreference
的子类,定义对话框中的内容,以及如何将对话框的内容存储到SharedPreference
值(以及从中检索)。我的 ColorMixer CWAC 项目 有一个
ColorPreference
,您可能希望检查一下。That is probably a custom
DialogPreference
that happens to have aTimePicker
in it.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) aSharedPreference
value.My ColorMixer CWAC project has a
ColorPreference
that you may wish to examine.