首页 > 其他分享 >过滤输入法的表情

过滤输入法的表情

时间:2022-11-29 15:09:18浏览次数:34  
标签:输入法 int 过滤 attrs context 表情


所以为了防止用户胡乱输入表情、同时限制用户只能输入应用自带的表情。编写了一个自定义控件来禁止输入的表情。

代码如下:



[java] ​​ view plain​​ ​​


  1. package
  2.   
  3. import
  4. import
  5. import
  6. import
  7. import
  8. import
  9. import
  10.   
  11. /**
  12.  * 过滤搜狗输入法或其他输入法 当中的图片或其他非法字符
  13.  * 
  14.  * 暂时仅过滤了部分常用的表情字符
  15.  * 
  16.  * @author QD
  17.  * 
  18.  */
  19.   
  20. public class MyEditText extends
  21.   
  22. int maxLength = -1;  
  23.   
  24. public MyEditText(Context context, AttributeSet attrs, int
  25. super(context, attrs, defStyle);  
  26.         addListener(attrs);  
  27.     }  
  28.   
  29. public
  30. super(context, attrs);  
  31.         addListener(attrs);  
  32.     }  
  33.   
  34. public
  35. super(context);  
  36. null);  
  37.     }  
  38.   
  39. private void
  40. if (attrs != null)  
  41. "http://schemas.android.com/apk/res/android", "maxLength", -1);  
  42. // 过滤输入法表情
  43. new
  44. @Override
  45. public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int
  46. new
  47. for (int
  48. char
  49. // 第一个字符为以下时,过滤掉
  50. if (c == 55356 || c == 55357 || c == 10060 || c == 9749 || c == 9917 || c == 10067 || c == 10024
  51. 11088 || c == 9889 || c == 9729 || c == 11093 || c == 9924) {  
  52.                         i++;  
  53. continue;  
  54. else
  55.                         buffer.append(c);  
  56.                     }  
  57.                 }  
  58. if (source instanceof
  59. new
  60. null, sp, 0);  
  61. return
  62. else
  63. return
  64.                 }  
  65.             }  
  66.         };  
  67. // 输入框长度限制
  68. if (maxLength > 0)  
  69. new InputFilter[] { filter, new
  70. else
  71. new
  72.     }  

标签:输入法,int,过滤,attrs,context,表情
From: https://blog.51cto.com/u_13657808/5895089

相关文章