【问题标题】:Programmatically setText color for linearLayout [duplicate]以编程方式为linearLayout设置文本颜色[重复]
【发布时间】:2017-01-02 01:31:22
【问题描述】:

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

【问题讨论】:

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


【解决方案1】:

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

【讨论】:

  • 谢谢,对我很有用。
【解决方案2】:
( (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);
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-18
    • 1970-01-01
    • 2014-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多