直播带货源码,android editText设置颜文字过滤
直播带货源码,android editText设置颜文字过滤
//给editText设置过滤器
InputFilter inputFilter = new InputFilter() {
//限制输入表情
Pattern emoji = Pattern.compile("[\ud83c\udc00-\ud83c\udfff]|[\ud83d\udc00-\ud83d\udfff]|[\u2600-\u27ff]|[\u2190-\u21FF]|[\u2600-\u26FF]|[\u2700-\u27BF]|[\u3000-\u303F]|[\u1F300-\u1F64F]|[\u1F680-\u1F6FF]", Pattern.UNICODE_CASE | Pattern.CASE_INSENSITIVE);
//限制输入特殊字符以及颜文字
String speChat = "[`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?]";
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
Matcher emojiMatcher = emoji.matcher(source);
if (emojiMatcher.find()) {
ToastUtils.showShorts(FinishPatrolActivity.this, "不支持输入表情");
return "";
}
Pattern pattern = Pattern.compile(speChat);
Matcher matcher = pattern.matcher(source.toString());
if (matcher.find()) {
ToastUtils.showShorts(FinishPatrolActivity.this, "不支持输入特殊符号");
return "";
}
return null;
}
};
使用方式
//给editText设置filter过滤器//添加LengthFilter限制最大输入字符数为50
editText.setFilters(new InputFilter[]{new InputFilter.LengthFilter(50),EditTextInputFilterUtils.inputFilter});
以上就是 直播带货源码,android editText设置颜文字过滤,更多内容欢迎关注之后的文章