所以为了防止用户胡乱输入表情、同时限制用户只能输入应用自带的表情。编写了一个自定义控件来禁止输入的表情。
代码如下:
[java] view plain
- package
- import
- import
- import
- import
- import
- import
- import
- /**
- * 过滤搜狗输入法或其他输入法 当中的图片或其他非法字符
- *
- * 暂时仅过滤了部分常用的表情字符
- *
- * @author QD
- *
- */
- public class MyEditText extends
- int maxLength = -1;
- public MyEditText(Context context, AttributeSet attrs, int
- super(context, attrs, defStyle);
- addListener(attrs);
- }
- public
- super(context, attrs);
- addListener(attrs);
- }
- public
- super(context);
- null);
- }
- private void
- if (attrs != null)
- "http://schemas.android.com/apk/res/android", "maxLength", -1);
- // 过滤输入法表情
- new
- @Override
- public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int
- new
- for (int
- char
- // 第一个字符为以下时,过滤掉
- if (c == 55356 || c == 55357 || c == 10060 || c == 9749 || c == 9917 || c == 10067 || c == 10024
- 11088 || c == 9889 || c == 9729 || c == 11093 || c == 9924) {
- i++;
- continue;
- else
- buffer.append(c);
- }
- }
- if (source instanceof
- new
- null, sp, 0);
- return
- else
- return
- }
- }
- };
- // 输入框长度限制
- if (maxLength > 0)
- new InputFilter[] { filter, new
- else
- new
- }
- }