android - 如何限制edittext只接受阿拉伯语|波斯语字母

时间:2017-08-02 07:02:45

标签: android android-edittext

我想让我的edittexf只接受阿拉伯语|波斯语字母,我已经编写了这段代码,但我无法限制它。

name.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        @Override
        public void afterTextChanged(Editable s) {
            String firstChar = name.getText().toString();
            char chars[] = firstChar.toCharArray();
            Boolean isEnglish = true;
            if (Character.UnicodeBlock.of(chars[0]) != Character.UnicodeBlock.BASIC_LATIN) {
                isEnglish = false;
            }
        }
    });

如何让edittext只接受阿拉伯字母?

1 个答案:

答案 0 :(得分:2)

这只是阿拉伯语的例子

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="text"
    android:digits="غظضذخثتشرقصفعسنملكيطحزوهدبا" />