androidmaterial-components-androidandroid-chips

Set background color of the material chip programmatically


Chip chip = new Chip(context);
chip.setBackgroundcolor(getResources().getColor(R.color.blue));

The above line gives the error:

java.lang.UnsupportedOperationException: Do not set the background resource; Chip manages its own background drawable.

Solution

  • You can set background color of material chip by following line (Kotlin)

    chip.chipBackgroundColor = getColorStateList(/*your preferred color*/)