Android:android.R.id.content 的用途是什么?
任何人都可以解释“android.R.id.content”的含义吗?
它的使用情况如何?
http://developer.android.com 没有任何解释。
public static final int 内容
自:API 级别 1常量值:16908290 (0x01020002)
Anybody could explain the meaning of "android.R.id.content" ?
How is it being used ?
http://developer.android.com does not have any explanation.
public static final int content
Since: API Level 1Constant Value: 16908290 (0x01020002)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
正如 Philipp Reichart 评论的:
以防万一任何需要的人,您都可以使用
binding 来通过 View Binding 获取此视图.root
As Philipp Reichart commented:
In case anyone need, you can get this view with View Binding by using
binding.root
continue
The
android.R.id.content
ID value indicates theViewGroup
of the entire content area of anActivity
.It can be used with
Fragment
:The code above will insert the
View
created byFragment
into theViewGroup
identified byandroid.R.id.content
.Google 设计师根据特定或推荐的设计指南来开发 Android UX。 The layout android.R.id.content defines a linearlayout with a few attributes Android believes are a good standard.
因此,使用 android.R.id.content 加载片段管理器的根视图可确保实现这些准则。
注意:此布局设置了属性:android:addStatesFromChildren="true"以允许子片段覆盖此根视图中的属性。
从版本 19 开始,android.R.id.content 在文件中定义:auto_complete_list.xml
Google designers develop Android UX with specific or recommended design guidelines. The layout android.R.id.content defines a linearlayout with a few attributes Android believes are a good standard.
Thus loading a Fragment Manager's root view with android.R.id.content ensures these guidelines are implemented.
NOTE: This layout has set the attribute: android:addStatesFromChildren="true" to allow child fragments to overwrite attributes in this rootview.
As of version 19, android.R.id.content is defined in a file: auto_complete_list.xml
来自片段示例
From Fragment Example
android.R.id.content 在需要视图时非常有用,例如:
Show Snackbar:
Fragment transaction
android.R.id.content is very useful for when you need a view, for example:
Show Snackbar:
Fragment transaction
人们已经给出了一个通用的定义,我想写一下通用的用法。如果您想在扩展至 BottomSheetDialog 或 Dialog 的类中使用小吃栏,通常是“valparentView =dialog?.window?.DecorView?.findViewById(android.R.id.content) ?: binding.root”,您可以需要使用,但“binding.root.rootView”也可以工作,而不是这样做。祝你有美好的一天。
People have made a general definition, and I would like to write about a general usage. If you want to use a snackbar in a class that extends to BottomSheetDialog or Dialog, it's usually "val parentView =dialog?.window?.DecorView?.findViewById(android.R.id.content) ?: binding.root" you may need to make use, but instead of doing this, "binding.root.rootView" will also work. Have a good day.