有人能解释一下"android.R.id.content“的意思吗?
它是如何被使用的?
http://developer.android.com没有任何解释。
公共静态最终int内容
自: API级别1
常量值: 16908290 (0x01020002)
发布于 2012-10-15 08:35:32
android.R.id.content
为您提供了视图的根元素,而不必知道其实际名称/类型/ID。请查看http://stackoverflow.com/questions/4486034/android-how-to-get-root-view-from-current-activity
发布于 2014-11-19 17:21:31
android.R.id.content
ID值指示Activity
的整个内容区域的ViewGroup
。
它可以与Fragment
一起使用
public class MyActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(android.R.id.content, MyFragment.newInstance())
.commit();
}
}
...
}
上面的代码将把Fragment
创建的View
插入到android.R.id.content
标识的ViewGroup
中。
发布于 2021-04-09 20:45:37
当您需要一个视图时,android.R.id.content非常有用,例如:
显示快捷栏:
Snackbar.make(activity.findViewById(android.R.id.content), MESSAGE, Snackbar.LENGTH_LONG).show();
片段事务
getSupportFragmentManager().beginTransaction()
.add(android.R.id.content, FragmnetTest.newInstance())
.commit();
https://stackoverflow.com/questions/7776768
复制相似问题