在Android的键盘上阻止ë,à,é,ä等字符

时间:2018-10-03 11:16:07

标签: java android android-input-filter

有没有一种方法可以使用输入过滤器阻止android中长按a,e,i等键时出现的ä等字符。

1 个答案:

答案 0 :(得分:0)

希望对您有帮助

private EditText editText;
private String characterSet = "give_blocking_charset_here";

private InputFilter filter = new InputFilter() {

    @Override
    public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {

        if (source != null && characterSet.contains(("" + source))) {
            return "";
        }
        return null;
    }
};

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    editText = (EditText) findViewById(R.id.editText);
    editText.setFilters(new InputFilter[] { filter });
}