Is there a way to do android:textColor
programmatically for linearLayout which contains bunch of textViews?
Asked
Active
Viewed 2,519 times
1

Burhanuddin Rashid
- 5,260
- 6
- 34
- 51

Nazerke
- 2,098
- 7
- 37
- 57
-
2Iterate over the children of the `LinearLayout`, calling `setTextColor()` on all children that are `instanceof TextView`. – CommonsWare Aug 25 '16 at 14:43
-
6http://stackoverflow.com/questions/7361135/how-to-change-color-and-font-on-listview – Vyacheslav Aug 25 '16 at 14:44
2 Answers
3
Assuming you have given id to your LinearLayout, this should work :
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));
}
}

Avin
- 81
- 4
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);
}
}

Nir Duan
- 6,164
- 4
- 24
- 38