使用自定义 com.android.internal.R.layout.preference
有没有办法设置android.preference.Preference的layoutResId?我需要用 ListView 以外的东西替换 com.android.internal.R.layout.preference 。 (我想要另一个视图中的 PreferenceActivity,并让它扩大该视图中的首选项层次结构,而不是仅显示默认的 ListView)。通过 PreferenceActivity 我可以获取 PreferenceManager,但 PreferenceManager.getPreferenceScreen 是包私有的。 PreferenceScreen.setLayoutResId可以更改我想要的ResId,但我无法获取它。如果可以的话,会改变这项工作还是会破坏一切?
Is there any way of setting the layoutResId of android.preference.Preference? I need to replace com.android.internal.R.layout.preference with something more than a ListView. (I want a PreferenceActivity in another view, and for it to inflate the hierarchy of preferences in that view instead of only showing the default ListView). Through PreferenceActivity I can get the PreferenceManager, but PreferenceManager.getPreferenceScreen is package-private. PreferenceScreen.setLayoutResId can change the ResId I want, but I can't get at it. If I could, would changing this work or would it break things?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只要布局中存在 ID 为
android.R 的
(或 XML 中的ListView
,您就可以在PreferenceActivity
上调用setContentView
。 id.list@android:id/list
)。这将是偏好被夸大的目标。只要满足此要求,您就可以自由添加您想要的任何其他视图。You can call
setContentView
on aPreferenceActivity
as long as there is aListView
somewhere in the layout with an ID ofandroid.R.id.list
(or@android:id/list
from XML). This will be the target into which preferences are inflated. You are free to add whatever other views you'd like as long as this requirement is met.