很遗憾,芯片不支持多行文本。下面是从 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);
}
我们尝试使用 AppCompatCheckBox
实现类似的行为,因为 chip 继承了同一类。
您可以使用 chip 类进行详细参考:https://github.com/material-components/material-components-android/blob/master/lib/java/com/google/android/material/chip/Chip.java