如何为 Android 创建带有微调器的弹出窗口?
我想创建一个弹出窗口,该窗口将在用户第一次打开应用程序时出现,并要求用户在微调器中选择设置(示例如下图所示)
另外,我会喜欢它自动弹出而不是需要按下按钮。可以这样做吗?
请帮忙。多谢。 =)
I would like to create a popup window which will appear the first time the user opens the application and ask the user to select the setting within a spinner (example something close like the picture below)
(source: mikesandroidworkshop.com)
Also, I would like it to popup automatically rather then having the need to press on a button. Is it possible to do so?
Please help. thanks a lot. =)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这就是所谓的对话框。请参阅此页面了解更多信息 http://developer.android.com/guide/topics /ui/dialogs.html。
要创建像您所示的对话框,请查看自定义对话框部分。基本上在 XML 文件中创建您想要在对话框内部看到的布局,并像使用 Activity 一样使用 setContentView 。
如果您希望它在活动启动时弹出,只需将代码放入活动的
onStart
方法中即可。That is called a Dialog. See this page for more info http://developer.android.com/guide/topics/ui/dialogs.html.
To create the one like you showed, look under the Custom Dialog section. Basically create the layout you want to see inside of the dialog in an XML file and use setContentView as you would with an activity.
If you want it to pop up when an activity starts just put the code in the
onStart
method in your activity.例如,只需将其称为 onCreate 即可。并使用共享首选项来检查首次启动。
当关闭弹出窗口时,只需更改 SharedPreferences 中的标志(您可能希望使弹出窗口不可取消)。
Just call it onCreate, for example. And use shared preferences to check for first time launch.
And when closing popup just change flag in SharedPreferences (you would probably will want to make popup not-cancelable).