获取activity下的所有view

来源:互联网 发布:作品集用什么软件知乎 编辑:程序博客网 时间:2024/05/21 07:54
/*** @note 获取该activity所有view* */public void getAll() {View view = current_activity.getWindow().getDecorView();List<View> all_child=getAllChildViews(view);
//……
//……
//do somthing
}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;}

0 0
原创粉丝点击