从文本观察器更改imeOptions

时间:2018-08-07 19:16:52

标签: android android-edittext imeoptions

我正在尝试从文本监视程序更改imeOptions,在检测到edittext上的“ @”符号时,我需要将其imeOptions从“ Go”更改为“ Done”。请指教。

 etSample.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            if ((charSequence+"").contains("@")){
                etSample.setBackgroundColor(Color.BLACK);
                etSample.setTextColor(Color.WHITE);
                etSample.setImeOptions(EditorInfo.IME_ACTION_NEXT);
                etSample.requestFocus();
            }else {
                etSample.setBackgroundColor(Color.WHITE);
                etSample.setTextColor(Color.BLACK);
                etSample.setImeOptions(EditorInfo.IME_ACTION_DONE);
                etSample.requestFocus();
            }
        }

        @Override
        public void afterTextChanged(Editable editable) {

        }
    });

这不起作用(它将始终显示为已完成)

1 个答案:

答案 0 :(得分:1)

尝试将etSample.requestFocus()替换为etSample.setInputType(InputType.TYPE_CLASS_TEXT)