The expression of the third-party input method may bring some trouble to the development, generally like the server upload characters are ordinary characters, but testing, is to take out Sogou input method, a few expressions,
Big problem came, either show the exception, or direct crash, but there are very few models, will support, may be the third-party ROM to the Android TextView do some processing, so, we can only kill the bloody expression of the specific method is as follows:
The first is to add Textwatcher to the Edittextview.
When judging the change of the character, the type of the character, whether it is a character, otherwise delete the original character, re-enter;
1Medittextview.addtextchangedlistener (NewTextwatcher () {2 3 @Override4 Public voidaftertextchanged (Editable Editable) {5 intindex = Contenttext.getselectionstart ()-1;6 if(Index > 0) {7 if(Isemojicharacter (Editable.charat (index))) {8Editable edit =Contenttext.gettext ();9Edit.delete (index, index + 1);Ten } One } A } - - @Override the Public voidBeforetextchanged (Charsequence S,intStartintCountintAfter ) { - - } - + @Override - Public voidOnTextChanged (Charsequence S,intStartintBefore,intcount) { + A } at});
Here is the judge whether the character is an expression;
1 Private Static boolean isemojicharacter (char codepoint) {2 return ! ( (codepoint = = 0x0) | | (codepoint = = 0x9) | | (codepoint = = 0xA) | | (codepoint = = 0xD) | | ((codepoint >= 0x20) && odepoint <= 0xd7ff)) | | ((codepoint >= 0xe000) && (codepoint <= 0xFFFD)) | | ((codepoint >= 0x10000) && (codepoint <= 0x10ffff)); 3 }
Android EditText Mask The expression of third-party IME