title: Dynamically add chips to chipgroup
body: <p>I'm trying to add several chips to the chip group dynamically. The first one appears fine but others do not appear properly. But when I do it using XML it works fine.</p>
  <p><a href="https://i.stack.imgur.com/W0NHe.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/W0NHe.jpg" alt="The last chip added is small, grey, and has no text. It should be orange and contain text like the first three." /></a></p>
  <p>activity_main.xml</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;HorizontalScrollView
              android:layout_width=&quot;350dp&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:scrollbars=&quot;none&quot;
              app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
              app:layout_constraintEnd_toStartOf=&quot;@+id/chips_select&quot;
              app:layout_constraintHorizontal_bias=&quot;0.0&quot;
              app:layout_constraintStart_toStartOf=&quot;parent&quot;
              app:layout_constraintTop_toBottomOf=&quot;@+id/textView&quot;
              app:layout_constraintVertical_bias=&quot;0.51&quot;&gt;
      &lt;com.google.android.material.chip.ChipGroup
                  android:id=&quot;@+id/chip_group_main&quot;
                  android:layout_width=&quot;wrap_content&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:layout_marginStart=&quot;8dp&quot;
                  android:layout_marginTop=&quot;2dp&quot;
                  app:chipSpacingHorizontal=&quot;4dp&quot;&gt;
          &lt;com.google.android.material.chip.Chip
                      style=&quot;@style/ChipTextAppearance&quot;
                      android:layout_width=&quot;wrap_content&quot;
                      android:layout_height=&quot;wrap_content&quot;
                      android:text=&quot;Hello&quot;
                      app:chipBackgroundColor=&quot;@color/colorAccent&quot;
                      app:closeIconEnabled=&quot;true&quot; /&gt;
          &lt;com.google.android.material.chip.Chip
                      style=&quot;@style/ChipTextAppearance&quot;
                      android:layout_width=&quot;wrap_content&quot;
                      android:layout_height=&quot;wrap_content&quot;
                      android:text=&quot;World&quot;
                      app:chipBackgroundColor=&quot;@color/colorAccent&quot;
                      app:closeIconEnabled=&quot;true&quot; /&gt;
      &lt;/com.google.android.material.chip.ChipGroup&gt;
  &lt;/HorizontalScrollView&gt;
  </code></pre>
  <p>In MainActivity.java</p>
  <pre class="lang-java prettyprint-override"><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
  
    Chip chip = new Chip(this);
    chip.setText(&quot;ABC&quot;);
    chip.setChipBackgroundColorResource(R.color.colorAccent);
    chip.setCloseIconVisible(true);
    chip.setTextColor(getResources().getColor(R.color.white));
    chip.setTextAppearance(R.style.ChipTextAppearance);
  
    Chip chip2 = new Chip(this);
    chip.setText(&quot;XYZ&quot;);
    chip.setChipBackgroundColorResource(R.color.colorAccent);
    chip.setCloseIconVisible(true);
    chip.setTextColor(getResources().getColor(R.color.white));
    chip.setTextAppearance(R.style.ChipTextAppearance);
  
    ChipGroup chipGroup = findViewById(R.id.chip_group_main);
  
    chipGroup.addView(chip);
    chipGroup.addView(chip2);
  }
  </code></pre>
  <p>style.xml</p>
  <pre><code>&lt;resources&gt;
      &lt;style name=&quot;AppTheme&quot; parent=&quot;Theme.MaterialComponents.Light.NoActionBar&quot;&gt;
          &lt;!-- Customize your theme here. --&gt;
          &lt;item name=&quot;colorPrimary&quot;&gt;@color/colorPrimary&lt;/item&gt;
          &lt;item name=&quot;colorPrimaryDark&quot;&gt;@color/colorPrimaryDark&lt;/item&gt;
          &lt;item name=&quot;colorAccent&quot;&gt;@color/colorAccent&lt;/item&gt;
      &lt;/style&gt;
      &lt;style name=&quot;ChipTextAppearance&quot; parent=&quot;TextAppearance.MaterialComponents.Chip&quot;&gt;
          &lt;item name=&quot;android:textColor&quot;&gt;@android:color/white&lt;/item&gt;
          &lt;item name=&quot;android:textSize&quot;&gt;12sp&lt;/item&gt;
      &lt;/style&gt;
  &lt;/resources&gt;
  </code></pre>
  <p>standalone_chip.xml</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;chip
      xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      app:chipBackgroundColor=&quot;@color/colorAccent&quot;
      app:closeIconEnabled=&quot;true&quot;
      style=&quot;@style/ChipTextAppearance&quot;
      app:closeIconTint=&quot;@android:color/white&quot; /&gt;
  </code></pre>