android 屏蔽emoji表情

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u014289767/article/details/79298859

要在edittext屏蔽emoji 只需要拦截输入就OK了 et_set_name是自己定义的edittext

et_set_name.setFilters(new InputFilter[]{new EmojiFilter()});

public class EmojiFilter implements InputFilter {

   private String content;
    Pattern pattern = Pattern.compile( "[\ud83c\udc00-\ud83c\udfff]|[\ud83d\udc00-\ud83d\udfff]|[\u2600-\u27ff]",  Pattern . UNICODE_CASE | Pattern . CASE_INSENSITIVE );
   
    public EmojiFilter(String content) {
      super();
      this.content = content;
   }
   
   
    public EmojiFilter() {
      
   }


   @Override
   public CharSequence filter(CharSequence sourse, int strat, int end,
         Spanned dest, int dstart, int dend) {
        Matcher matcher = pattern.matcher(sourse);
         if(matcher.find()  ){
              return "" ;
          }
         return null;
    }
   
    
}

ok 就是这样

展开阅读全文

没有更多推荐了,返回首页