Modify build.gradle file, add XEditText to your project:
dependencies{
compile 'com.xw.repo:xedittext:2.0.0@aar'
}
after that, in your layout.xml:
<com.xw.repo.XEditText
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:x_disableEmoji="true"/>
Or:
Customize EditText like this:
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;
}
}
}
Both will work well !
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…