有没有办法以编程方式为包含一堆textViews的linearLayout执行android:textColor
?
答案 0 :(得分:2)
假设您已为您的LinearLayout指定了ID,那么这应该有效:
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.linear_layout);
TextView textView;
for (int i=0; i<linearLayout.getChildCount();i++)
{
View view = linearLayout.getChildAt(i);
if (view instanceof TextView){
textView = (TextView) view;
textView.setTextColor(getResources().getColor(R.color.colorAccent));
}
}
答案 1 :(得分:0)
( (ViewGroup) findViewById(android.R.id.content));
for (int i = 0; i < count; i++) {
View view = viewGroup.getChildAt(i);
if (view instanceof TextView){
TextView text= (TextView) view;
text.setTextColor(Color.WHITE);
}
}