private void addLengthFilter(EditText editText) {
editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(20) {
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
CharSequence sequence = super.filter(source, start, end, dest, dstart, dend);
if (sequence == null) return null;
if (!TextUtils.equals(sequence, source)) {
ToastUtil.showMessage("备注长度最多支持20字");
}
return sequence;
}
}});
}
网友评论