Android:如何使用 NumberPickerDialog
有人可以给我一个如何在 Activity.onCreateDialog 中实例化 NumberPickerDialog 的示例吗?(https://github.com/novak/numberpicker/blob/master/lib/src/com/michaelnovakjr/numberpicker/NumberPickerDialog.java)?
名为 numberpicker-demo 的存储库中有使用该小部件的示例,但没有用于实际对话框的示例。
在我尝试过的其他方法中,尝试过类似的方法:
return new NumberPickerDialog.Builder(this)
.setTitle("Choose Number")
.etc..
但这仅显示一个标准的 AlertDialog,没有 NumberPicker。
谢谢!
Could someone give me an example of how to instantiate a NumberPickerDialog within Activity.onCreateDialog ?(https://github.com/novak/numberpicker/blob/master/lib/src/com/michaelnovakjr/numberpicker/NumberPickerDialog.java) ?
There are examples in a repo called numberpicker-demo for using the widget, but none for the actual dialog.
Amongst other approaches I've tried tried something like:
return new NumberPickerDialog.Builder(this)
.setTitle("Choose Number")
.etc..
But this just shows a standard AlertDialog, without the NumberPicker.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
最终让它发挥作用。 com.quietlycoding.android.picker.Picker 中有一个示例,但我发现该对话框没有正确设置调光,在视图中时将背景中的整个 Activity 涂黑。
我通过简单地以通常的方式创建一个 AlertDialog,然后将 NumberPicker 小部件粘贴到 setView() 中来解决这个问题:
确保将 number_picker_pref.xml 从 numberpicker 项目复制到您自己项目中的 res/layout 中。
Got it working eventually. There's an example in com.quietlycoding.android.picker.Picker, but I've found that the dialog doesn't set the dimming properly, blacking out the whole Activity in the background while it's in view.
I worked around this by simply creating an AlertDialog in the usual way, and then just sticking a NumberPicker widget into setView():
Make sure to copy number_picker_pref.xml from the numberpicker project to res/layout in your own project.
看看这个(以及
可选这个:
创建对话框)。
Look at this (and
optionaly this:
Creating dialogs).
如果您这样做,那就会简单得多:
将此代码添加到您的 Activity
That should be much simpler if only you do this:
Add this code on your Activity