获得activity的rootview

来源:互联网 发布:什么赚钱软件最好 编辑:程序博客网 时间:2024/06/05 14:46
   @NonNull    public static FrameLayout getRootFrame(@NonNull Activity activity) {        View re = activity.findViewById(android.R.id.content);        if (re != null && re instanceof FrameLayout) {            return (FrameLayout) re;        }        ViewGroup viewGroup = (ViewGroup) activity.getWindow().getDecorView();        re = viewGroup.getChildAt(viewGroup.getChildCount() - 1);        if (re != null && re instanceof FrameLayout) {            return (FrameLayout) re;        } else {            re = new FrameLayout(activity);            activity.getActionBar().getHeight();            ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT                    , ViewGroup.LayoutParams.MATCH_PARENT);            viewGroup.addView(re, lp);            return (FrameLayout) re;        }    }
0 0
原创粉丝点击