This is how I make a static ChipGroup
<com.google.android.material.chip.ChipGroup
android:id="@+id/chip_group_filter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/searchPromo"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_marginRight="10dp"
app:singleSelection="false">
<com.google.android.material.chip.Chip
android:id="@+id/chpFoodcourt"
style="@style/Widget.MaterialComponents.Chip.Filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Foodcourt"
android:textColor="#0088BE"
app:chipStrokeColor="#0088BE"
app:chipStrokeWidth="1dp" />
<com.google.android.material.chip.Chip
android:id="@+id/chpParking"
style="@style/Widget.MaterialComponents.Chip.Filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Parking"
android:textColor="#0088BE"
app:chipStrokeColor="#0088BE"
app:chipStrokeWidth="1dp" />
<com.google.android.material.chip.Chip
android:id="@+id/chpRestaurant"
style="@style/Widget.MaterialComponents.Chip.Filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Restaurant"
android:textColor="#0088BE"
app:chipStrokeColor="#0088BE"
app:chipStrokeWidth="1dp" />
<com.google.android.material.chip.Chip
android:id="@+id/chpRetail"
style="@style/Widget.MaterialComponents.Chip.Filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Retail"
android:textColor="#0088BE"
app:chipStrokeColor="#0088BE"
app:chipStrokeWidth="1dp" />
<com.google.android.material.chip.Chip
android:id="@+id/chpGame"
style="@style/Widget.MaterialComponents.Chip.Filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Game"
android:textColor="#0088BE"
app:chipStrokeColor="#0088BE"
app:chipStrokeWidth="1dp" />
<com.google.android.material.chip.Chip
android:id="@+id/chpCafe"
style="@style/Widget.MaterialComponents.Chip.Filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cafe"
android:textColor="#0088BE"
app:chipStrokeColor="#0088BE"
app:chipStrokeWidth="1dp" />
<com.google.android.material.chip.Chip
android:id="@+id/chpFashion"
style="@style/Widget.MaterialComponents.Chip.Filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Fashion"
android:textColor="#0088BE"
app:chipStrokeColor="#0088BE"
app:chipStrokeWidth="1dp" />
<com.google.android.material.chip.Chip
android:id="@+id/chpHospital"
style="@style/Widget.MaterialComponents.Chip.Filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hospital"
android:textColor="#0088BE"
app:chipStrokeColor="#0088BE"
app:chipStrokeWidth="1dp" />
</com.google.android.material.chip.ChipGroup>
Then, instead having hardcoded Chips, I want to fetch the fitch list from API, like this:
val interestList = arguments?.getStringArrayList("INTEREST_LIST")
interestList.forEach {
val theChip = Chip(requireActivity())
theChip.text = it.toString()
theChip.isCheckable = true
theChip.isClickable = true
theChip.setTextColor(Color.parseColor("#0088BE"))
//theChip.setTextAppearanceResource(R.style.Widget_Material3_Chip_Filter)
chipGroupFilter.addView(theChip)
}
And here's the result. The chip list is fetched correctly, except the rounded rectangle border isn't drawn.
Yes, the border only appears after it's clicked, though
How to make the rounder rectangle border always visible?