sjngm
sjngm

Reputation: 12861

Android: How to turn off IME for an EditText?

How do I turn off the IME-functionality of an EditText?

Or: How do I avoid the display of the IME-keyboard?

I have a layout where my special keyboard sits below the EditText so there's no need to show the IME. Please understand that I cannot implement my keyboard as IME as it is specific for this very EditText and using it in any other context would only cause problems.

I tried to use

getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

in the onCreate() of the activity, but that doesn't seem to do anything in this situation.

Upvotes: 3

Views: 7687

Answers (3)

betorcs
betorcs

Reputation: 2821

editText.setInputType(EditorInfo.TYPE_NULL);

Upvotes: 2

Reuben Scratton
Reuben Scratton

Reputation: 38707

Think I found a way to do it... subclass EditText and override onCheckIsTextEditor() to return false:

public class EditTextEx extends EditText {

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

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

I've tested it and I can't get the soft keyboard to show at all.

Upvotes: 6

sjngm
sjngm

Reputation: 12861

While trying to get it working 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 get called, but neither hide the IME-pop-up.

Upvotes: 0

Related Questions