2016-08-25 7 views
1

android:textColorは、textViewsの束を含むlinearLayoutに対してプログラム的に行う方法はありますか?あなたのLinearLayoutにIDを与えていると仮定すると、programmatically linearLayoutのテキスト色

+2

反復、()を ''あるのTextView instanceofは、すべての子どもたちに'。 – CommonsWare

+6

http://stackoverflow.com/questions/7361135/how-to-change-color-and-font-on-listview – Vyacheslav

答えて

2

、これは動作するはずです:SETTEXTCOLOR `呼び出す` 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)); 
     } 
    } 
+0

ありがとう、それは私には役に立ちました。 – MyMy

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