Android 遍历Activity所有的View

1.//获取activity所有的子view

    //获取activity所有的子view
    private List getAllViews(){
        List viewList=new ArrayList<>();
        ViewGroup decorView = (ViewGroup) getWindow().getDecorView();
        for(int i=0;i

2.//递归设置所有父布局为透明背景

    //递归设置所有父布局为透明背景
    private void setViewGroupTransparent(View view) {
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        if (view instanceof ViewGroup) {
            ViewGroup vp = (ViewGroup) view;
            vp.setBackgroundColor(Color.TRANSPARENT);
            for (int i = 0; i < vp.getChildCount(); i++) {
                View childAt = vp.getChildAt(i);
                if (childAt instanceof ViewGroup) {
                    childAt.setBackgroundColor(Color.TRANSPARENT);
                    setViewGroupTransparent(childAt);
                }
            }
        }
    }

你可能感兴趣的:(android,android,activity所有view)