在 Android 上的警报对话框中显示首选项
我知道 Android 能够创建一个 Activity 来更新共享首选项,但是有没有办法在警报对话框中显示该“Activity”,以便首选项可以显示为“弹出窗口”,而不是切换到自己的 Activity ?
我希望这是有道理的......
I know that Android has the ability to create an Activity for updating shared preferences, but is there a way to display that "Activity" in an alert dialog so that the preferences can appear as a "popup" instead of switching out to its own activity?
I hope this makes sense....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我从未尝试过使用 PreferencesActivity,但您可以在 AndroidManifest.xml 示例中使用
android:theme="@android:style/Theme.Dialog"
使普通 Activity 显示为弹出对话框正如我所说,不确定它是否适用于 PreferencesActivity。
I've never tried it with a PreferencesActivity, but you can make a normal Activity appear as a popup dialog using
android:theme="@android:style/Theme.Dialog"
in your AndroidManifest.xml exampleAs I said, not sure if it'll work with a PreferencesActivity.
可以使用警报对话框来管理您的某些首选项。但只有当您只需设置一点偏好时,我才会推荐此选项。
因为您必须自己存储和加载首选项,所以 PreferenceActivity 会自动为您完成此操作。
完成此操作所需的资源是 AlertDialog 页面 和简介共享首选项
然后只需监听
onClick( )
在警报对话框中并设置您的首选项。It is possible to use an alert dialog to manage some of your preferences. But I would only recommend this if you only have to set one little preference.
Because you'll have to store and load the preferences yourself, a PreferenceActivity would do this automatically for you.
The resources you need to accomplish this is the AlertDialog page and an introduction to Shared Preferences
Then simply listen for
onClick()
in the alert dialog and set your preference.