警报对话框内的首选项活动
我可以在警报对话框中填充 PreferenceScreen 吗?
这就是我尝试过的:
final LayoutInflater factory = LayoutInflater.from(this);
final View myDialog = factory.inflate(R.xml.prefScr, null);
final Dialog dialog = new AlertDialog.Builder(this)
.setTitle("This is Dialog")
.setView(myDialog)
.create();
这给了我例外:
android.view.InflateException: Binary XML file line #2: Error inflating class PreferenceScreen
Can I inflate PreferenceScreen inside an alert dialog?
This is what I've tried:
final LayoutInflater factory = LayoutInflater.from(this);
final View myDialog = factory.inflate(R.xml.prefScr, null);
final Dialog dialog = new AlertDialog.Builder(this)
.setTitle("This is Dialog")
.setView(myDialog)
.create();
this gives me exception:
android.view.InflateException: Binary XML file line #2: Error inflating class PreferenceScreen
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为不可能像这样在
PreferenceActivity
之外使用PreferenceScreen
...但这里有一些替代方案:1)制作
Activity
通过使用Manifest
中的样式显示为对话框:2) 按照当前的方式使用
AlertDialog
,但使用您自己的自定义布局对其进行扩充,该布局具有与您相同的功能PreferenceScreen
确实如此。然后您将必须手动管理首选项的获取和设置。3) 只需使用
PreferenceActivity
及其自己的PreferenceDialog
。这可能与您真正想要的不同,但使用PreferenceActivity
将为您节省大量手动处理所有首选项的工作。I don't think it is possible to use a
PreferenceScreen
outside of aPreferenceActivity
like this...but here are a few alternatives:1) Make the
Activity
appear as a dialog by using a style in yourManifest
:2) Use an
AlertDialog
as you currently are but inflate it with your own custom layout that has the same features as youPreferenceScreen
does. Then you would have to manage the getting and setting of preferences manually.3) Just use a
PreferenceActivity
with its ownPreferenceDialog
. This might not really be the same thing that you want, but using aPreferenceActivity
will save you a lot of the work of manually handling all of your preferences.