以编程方式为 linearLayout 设置文本颜色

Programmatically setText color for linearLayout

有没有办法以编程方式为包含一堆 textView 的 linearLayout 执行 android:textColor

( (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);
        }
    }

假设您已经为您的 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));
        }
    }