android遍历控件

//遍历当前界面所有控件

public List getAllChildViews(){

View view= this.getWindows.getDecorView();

return getAllChildViews(view);

}


//遍历一个ViewGroup

public LIst getAllChildViews(View view){

List views = new ArrayList();

if(view instanceof ViewGroup){

ViewGroup vp = (ViewGroup)view;

for(int i = 0;i

View viewchild=vp.getChildAt(i);

views.add(viewchild);

views.addAll(getAllChildViews(viewchild)));

}

}

return views;

}

你可能感兴趣的:(android,控件,遍历)