Hide soft keyboard when an EditText field receives focus

I am currently developing an enterprise Android application, which is deployed on devices that have a hardware keyboard. Most of the EditText fields require numerical input, so naturally it is much more convenient and faster to enter the data via the hardware keyboard. The problem is the soft keyboard pops up automatically when an EditText field receives focus and sometimes obscures the currently focused field and other parts of the screen.

My question is how can i prevent the poping up of the soft keyboard when an EditText field receives focus.

And the second question is how can i still show the soft keyboard on some other event, for example on long click on an EditText field.

Thank you!


Hiding soft keyboard forever:

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

To show after hiding "forever":

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
InputMethodManager im = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
im.showSoftInput(myEditText, 0);
链接地址: http://www.djcxy.com/p/93350.html

上一篇: 如果软件键盘在Android设备上可见,如何检测?

下一篇: 当EditText字段获得焦点时隐藏软键盘