1. getWindow().getDecorView().findViewById(android.R.id.content)
2. private static View getRootView(Activity context)
{
return ((ViewGroup)context.findViewById(android.R.id.content)).getChildAt(0);
}
本文提供了两种在Android中获取Activity根布局的方法。第一种方法直接通过getWindow().getDecorView().findViewById(android.R.id.content)获取。第二种方法则通过定义一个静态方法getRootView返回((ViewGroup)context.findViewById(android.R.id.content)).getChildAt(0),从而实现获取根布局。
1. getWindow().getDecorView().findViewById(android.R.id.content)
2. private static View getRootView(Activity context)
{
return ((ViewGroup)context.findViewById(android.R.id.content)).getChildAt(0);
}您可能感兴趣的与本文相关内容

被折叠的 条评论
为什么被折叠?