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