获取Android activity上所有的控件

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

在android开发中,在表单提交的场景下想获取activity上所有的控件

/**
     * @note 获取该activity所有view
     * @author liuh
     * */
    public List<View> getAllChildViews() {
        View view = this.getWindow().getDecorView();
        return getAllChildViews(view);
    }

    private List<View> getAllChildViews(View view) {
        List<View> allchildren = new ArrayList<View>();
        if (view instanceof ViewGroup) {
            ViewGroup vp = (ViewGroup) view;
            for (int i = 0; i < vp.getChildCount(); i++) {
                View viewchild = vp.getChildAt(i);
                allchildren.add(viewchild);
                allchildren.addAll(getAllChildViews(viewchild));
            }
        }
        return allchildren;
    }