Android: How to disable IME for EditText?

How to disable IME functionality EditText?

Or: How to avoid displaying the IME keyboard?

I have a layout where my special keyboard sits below EditText, so there is no need to show IME. Please understand that I cannot implement my keyboard as IME, since it is specific to this EditText, and using it in any other context can cause problems.

I tried to use

getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

in onCreate()activity, but it is not like anything in this situation.

+3
source share
3 answers

, ... subclass EditText onCheckIsTextEditor() false:

public class EditTextEx extends EditText {

    public EditTextEx(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override 
    public boolean onCheckIsTextEditor() {
        return false;
    }       
}

, .

+5
editText.setInputType(EditorInfo.TYPE_NULL);
+2

When trying to make it work, I also tried:

inputField.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
        }
    });

inputField.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View view, MotionEvent event) {
        getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
        return false;
    }
});

Both are called, but do not hide the IME popup.

0
source

Source: https://habr.com/ru/post/1773783/


All Articles