Android:如何在首选项屏幕中使用按钮
我想在 PreferenceActivity 中提供一个按钮。用户应该能够设置 时间(例如通过 TimePicker),但没有 ButtonPreference 或类似的东西。我不想使用 EditTextPreference。
那么我是否必须在 PreferenceActivity 中使用默认按钮并手动保存它的设置?
问候,
科迪
I'd like to provide a Button in the PreferenceActivity. The user should be able to set a
time (e.g. via TimePicker), but there's no ButtonPreference or something like that. I don't want to use EditTextPreference.
So do I have to use a default Button in the PreferenceActivity and save the settings for it manually?
Regards,
cody
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
创建一个包含
TimePicker
小部件的自定义DialogPreference
。无需按钮。代码应少于 100 行。这是一个示例项目,其中显示了自定义
ColorPreference
。Create a custom
DialogPreference
that incorporates aTimePicker
widget. No button required. Should be under 100 lines of code.Here is a sample project showing, among other things, a custom
ColorPreference
.您可以将按钮放在 Activity_layout.xml 中。例如,如果“Activity_Setup.java”是您的设置活动,“activity_setup.xml”是其布局,“myprefs.xml”是存储您的首选项布局的文件,那么
您应该将按钮放在“activity_setup.xml”中" 在列表下,最好在 TableRow 中,如下所示:
You can put the button in the activity_layout.xml . For example, if "Activity_Setup.java" is your setup activity, "activity_setup.xml" is its layout, and "myprefs.xml" is the file where your preference layout is stored, then
your should put the button in "activity_setup.xml" under the list, most preferable in a TableRow, like this: