以编程方式为linearLayout设置textText颜色

时间:2016-08-25 14:41:26

标签: android android-layout android-text-color

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

2 个答案:

答案 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);
        }
    }