怎么遍历view中的所有的控件
展开全部
获取总得TabLayout, 强转成ViewGroup,传入下面方法
private void getButtons(ViewGroup viewGroup) {
if (viewGroup == null) {
return;
}
int count = viewGroup.getChildCount();
for (int i = 0; i < count; i++) {
View view = viewGroup.getChildAt(i);
if (view instanceof Button) { // 若是Button记录下
Button newDtv = (Button) view;
} else if (view instanceof ViewGroup) {
// 若是布局控件(LinearLayout或RelativeLayout),继续查询子View
this.getButtons((ViewGroup) view);
}
}
}
private void getButtons(ViewGroup viewGroup) {
if (viewGroup == null) {
return;
}
int count = viewGroup.getChildCount();
for (int i = 0; i < count; i++) {
View view = viewGroup.getChildAt(i);
if (view instanceof Button) { // 若是Button记录下
Button newDtv = (Button) view;
} else if (view instanceof ViewGroup) {
// 若是布局控件(LinearLayout或RelativeLayout),继续查询子View
this.getButtons((ViewGroup) view);
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询