Программно установленный цвет текста для linearLayout
Есть ли способ сделать android:textColor
программно для linearLayout, который содержит кучу textViews?
2 ответа
Решение
Предполагая, что вы дали идентификатор для вашего LinearLayout, это должно работать:
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));
}
}
( (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);
}
}