算法把rootview中所有的button改变背景

来源:互联网 发布:淘宝瑕疵冰箱上当受骗 编辑:程序博客网 时间:2024/06/05 18:24
if (view == null || !(view instanceof ViewGroup))
return; 
Stack m = new Stack<>();
while (view != null) { 
ViewGroup tmpGroup = (ViewGroup) view; 
int count = tmpGroup.getChildCount(); 
for (int i = 0; i < count; i++) {
View child = tmpGroup.getChildAt(i);
if (child instanceof ViewGroup) m.add(child); 
else if (child instanceof Button) { child.setBackgroundColor(color);
} } 
if (m.isEmpty()) break; 
else view = m.pop();

}
阅读全文
0 0
原创粉丝点击