0

I am creating Chips dynamically and everything is working fine but when I set isCloseIconVisible and add the chip to ChipGroup then there is some kind of empty space(like margin not padding) at start of chip.

How can I resolve that? Any help will be appreciated

This is how I am creating Chip

fun createChip(context: Context, text: String, closeIconVisible: Boolean = true): Chip {
    val chip = Chip(context)
    chip.text = text
    chip.setChipDrawable(ChipDrawable.createFromAttributes(context, null, 0, 
              R.style.Widget_MaterialComponents_Chip_Entry))
    chip.setChipBackgroundColorResource(android.R.color.transparent)
    chip.isCheckedIconVisible = false
    chip.setTextColor(context.getColor((R.color.theme_primary)))
    chip.setCloseIconTintResource(R.color.theme_primary)
    chip.setBackgroundResource(R.drawable.style_rectangle_border)
    chip.setChipStrokeColorResource(R.color.theme_primary)
    chip.chipStrokeWidth = ProductConstants.CHIP_STROKE_WIDTH
    chip.isCloseIconVisible = closeIconVisible
    chip.isEnabled = closeIconVisible
    return chip
}
Zohab Ali
  • 8,426
  • 4
  • 55
  • 63

1 Answers1

0

I was creating chips programmatically so i had to do this in kotlin for each chip:

chip.minimumWidth = 0
chip.setEnsureMinTouchTargetSize(false)

To read more about how you can set horizontal and vertical spacing here is the official doc

Zohab Ali
  • 8,426
  • 4
  • 55
  • 63