Android EditText : How to avoid user enter smileys?

本小妞迷上赌 提交于 2019-12-14 04:25:15

问题


I would like to avoid to the user to put a smiley with the keyboard into an EditText. Is it possible ?


回答1:


You can define your input type and only accept letters or change your keyboard type:

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?




回答2:


Editing answer from here.

This will allow only ASCII characters to be entered in EditText.

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 "";
    }
 }
});


来源:https://stackoverflow.com/questions/24447928/android-edittext-how-to-avoid-user-enter-smileys

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!