简体   繁体   English

Android EditText:如何避免用户输入表情符号?

[英]Android EditText : How to avoid user enter smileys?

I would like to avoid to the user to put a smiley with the keyboard into an EditText . 我想避免让用户将键盘上的笑脸带入EditText Is it possible ? 可能吗 ?

在此输入图像描述

Editing answer from here . 这里编辑答案。

This will allow only ASCII characters to be entered in EditText. 这将只允许在EditText中输入ASCII字符。

edittext.setFilters(new InputFilter[] {
 new InputFilter() {
    public CharSequence filter(CharSequence src, int start,
            int end, Spanned dst, int dstart, int dend) {
        if(src.equals("")){ // for backspace
            return src;
        }
        if(src.toString().matches("[\\x00-\\x7F]+")){
            return src;
        }
        return "";
    }
 }
});

You can define your input type and only accept letters or change your keyboard type: 您可以定义输入类型,只接受字母或更改键盘类型:

https://developer.android.com/training/keyboard-input/style.html https://developer.android.com/training/keyboard-input/style.html

Or you can only accept some specific digits: 或者您只能接受一些特定的数字:

How to create EditText accepts Alphabets only in android? 如何创建EditText仅在android中接受Alphabets?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM