Android: Disable soft keyboard at all EditTexts

2020-01-25 01:17发布

I am working on a dialog at Android with a few EditTexts. I've put this line at the onCreate() in order to disable the soft keyboard:

Keypad.this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

The problem is that it works only when the dialog appear and doing nothing. When I move to the next EditText, the keyboard appears and not going down.

Does anybody have an idea how to solve this issue?

13条回答
\"骚年 ilove
2楼-- · 2020-01-25 01:53

I have been looking for solutions to this all day, and I came across this approach. I'm putting it here because it seems to answer this question perfectly.

EditText et = ... // your EditText
et.setKeyListener(null) //makes the EditText non-editable so, it acts like a TextView.

No need to subclass. The main difference between this and making your EditText non-focusable, is that the EditText still has its own cursor - you can select text, etc. All it does is suppress the IME from popping up its own soft keyboard.

查看更多
登录 后发表回答