0

我想用这种方式写unicode字符:EditText

final EditText et = (EditText) findViewById(R.id.editText1);
    TextWatcher tw = new TextWatcher() {
        public void afterTextChanged(Editable s){

        }
        public void  beforeTextChanged(CharSequence s, int start, int count, int after){

        }
        public void  onTextChanged (CharSequence s, int start, int before,int count) {
            if(s.equals("a")){
                et.append("\u0627");
            }
        } 
    };

    et.addTextChangedListener(tw);

但这只会写英文chracterEditText如何解决这个问题。提前致谢。

4

1 回答 1

1

试试这个方法可能对你有帮助

EditText edt = (EditText) findViewById(R.id.edt);


        InputFilter filter = new InputFilter() {

            @Override
            public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
                if(source.toString().equals("a")){
                    return "\u0627";
                }

                return null;

            }
        };

        edt.setFilters(new InputFilter[]{filter});

输出

在此处输入图像描述

于 2013-09-28T09:24:55.340 回答