没有弃用方法的首选项
我正在尝试(正确地)实现首选项屏幕,但问题是用于从 xml 文件读取首选项的所有方法均已弃用(或者我只是无法识别它们)。开发网站 (PreferenceActivity) 上的官方示例代码使用了已弃用的方法。有没有人找到了一种使用 xml 文件实现首选项屏幕但不使用 addPreferencesFromResource(int) 或 findPreference(CharSequence) 的方法?或者这些方法是否只是被标记为已弃用而尚未实现替代方案?
编辑:针对 Android 版本 2.1 进行开发
I'm trying to (correctly) implement a preferences screen, but the problem is that all the methods used to read preferences from xml files are deprecated (or I just don't recognize them). The official sample code on the dev site (PreferenceActivity) uses deprecated methods. Has anyone found out a way to implement a preferences screen with an xml file but without using either: addPreferencesFromResource(int) or findPreference(CharSequence)? Or have the methods just been marked deprecated without implementing the alternative yet?
EDIT: Developing for Android version 2.1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么它被弃用以及替代方案是什么在文档中得到了很好的解释:
换句话说,如果您想兼容 HONEYCOMB,那么您应该为您的 PreferenceFragment 使用代码>偏好活动。有关如何使用片段的详细说明可以在开发指南中找到。
Why its deprecated and what is the alternative is pretty well explained in documentation:
In other words, if you want to be HONEYCOMB compliant, then you should use PreferenceFragment for your
PreferenceActivity
. A detailed explanation on how to use fragments can be found in dev guide.在 Android 3 API Level 11 中,引入了基于片段的偏好模型,因此弃用了“与现代基于片段的 PreferenceActivity 不相关”的方法。
由于在线参考是最新版本,因此它显示这些方法已被弃用。通过操作 API 级别下拉列表,您可以标记给定 Android 版本中不存在的方法,但它不会更新描述以匹配,这就是它仍然显示为已弃用的原因。
如果您不打算支持 Android 3+,则应该使用旧方法,因为基于片段的解决方案不适用于在此之前的版本。
In Android 3, API Level 11, the fragment-based preference model was introduced, thus deprecating methods that "is not relevant for a modern fragment-based PreferenceActivity."
Since the online reference is the latest version, it shows the methods as deprecated. By manipulating the API Level dropdown, you can mark the methods that are not in the given Android version, but it doesn't update the descriptions to match, which is why it still shows up as deprecated.
If you don't plan on supporting Android 3+ you should just use the old methods, as the fragment-based solutions will not work to versions prior to this.