当输入类型为textpassword时,如何从软输入键盘中​​删除表情符号选项

时间:2016-09-20 11:54:22

标签: android passwords android-5.0-lollipop android-softkeyboard emoji

当我尝试输入密码时,我在软键盘输入中获得了表情符号选项。所以如果输入类型是 textpassword

,那么任何人都知道如何从软输入键盘中​​删除这个表情符号选项

screen one

screen two

1 个答案:

答案 0 :(得分:2)

自定义视图。

    public class CustomEditText extends EditText {
    public CustomEditText(Context context) {
        super(context);
        init();
    }

    public CustomEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public CustomEditText(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        setFilters(new InputFilter[]{new EmojiExcludeFilter()});
    }

    private class EmojiExcludeFilter implements InputFilter {

        @Override
        public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
            for (int i = start; i < end; i++) {
                int type = Character.getType(source.charAt(i));
                if (type == Character.SURROGATE || type == Character.OTHER_SYMBOL) {
                    return "";
                }
            }
            return null;
        }
    }
}