Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ChipGroup : Multiline text in Chips

Tags:

android

In an Android app, I need to create clickable chips within a Chat bubble (see image below).

enter image description here

I have added a ChipGroup below the TextView but since the text for chips is too long, it is getting clipped.

Any idea how I can have a multiline text in Chip or any workaround for this?

like image 321
Abdullah Avatar asked Mar 19 '19 09:03

Abdullah


1 Answers

Unfortunately chips does not support multiline text. Below is the reference from Chip.java

@Override
public void setSingleLine(boolean singleLine) {
    if (!singleLine) {
          throw new UnsupportedOperationException("Chip does not support multi-line text");
    }
    super.setSingleLine(singleLine);
}

@Override
public void setLines(int lines) {
    if (lines > 1) {
          throw new UnsupportedOperationException("Chip does not support multi-line text");
    }
    super.setLines(lines);
}

@Override
public void setMinLines(int minLines) {
    if (minLines > 1) {
         throw new UnsupportedOperationException("Chip does not support multi-line text");
    }
    super.setMinLines(minLines);
}

@Override
public void setMaxLines(int maxLines) {
    if (maxLines > 1) {
         throw new UnsupportedOperationException("Chip does not support multi-line text");
    }
    super.setMaxLines(maxLines);
}

However we trying to implement the similar behaviour with AppCompatCheckBox as chip inherits the same class.

You can use chip class for detail reference :https://github.com/material-components/material-components-android/blob/master/lib/java/com/google/android/material/chip/Chip.java

like image 147
Gopal Avatar answered Oct 17 '22 09:10

Gopal