简体   繁体   English

在Android上的警报对话框中显示首选项

[英]Display preferences in an alert dialog on Android

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? 我知道Android能够创建一个用于更新共享首选项的Activity,但有没有办法在警告对话框中显示“Activity”,以便首选项可以显示为“弹出窗口”,而不是切换到自己的活动?

I hope this makes sense.... 我希望这是有道理的....

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 example 我从未尝试过使用PreferencesActivity,但你可以在AndroidManifest.xml示例中使用android:theme="@android:style/Theme.Dialog"将正常的Activity显示为弹出对话框

<activity
    android:name=".MyPrefsActivity"
    android:label=""
    android:theme="@android:style/Theme.Dialog">
</activity>

As I said, not sure if it'll work with a PreferencesActivity. 正如我所说,不确定它是否适用于PreferencesActivity。

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. 因为您必须自己存储和加载首选项,所以PreferenceActivity会自动为您执行此操作。

The resources you need to accomplish this is the AlertDialog page and an introduction to Shared Preferences 完成此任务所需的资源是AlertDialog页面共享首选项简介

Then simply listen for onClick() in the alert dialog and set your preference. 然后只需在警告对话框中侦听onClick()并设置您的首选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM