androidandroid-layoutandroid-text-color

Programmatically setText color for linearLayout


Is there a way to do android:textColor programmatically for linearLayout which contains bunch of textViews?


Solution

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