2

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!

Evgeni Ivanov
  • 198
  • 2
  • 9
  • Possible duplicate of [Close/hide the Android Soft Keyboard](http://stackoverflow.com/questions/1109022/close-hide-the-android-soft-keyboard) – Suhas Bachewar Feb 10 '16 at 13:26
  • No, that question is about just hiding the keyboard, and he is able to show when you press a editText again. Here the question is about hiding the keyboard to not show anymore. – Ricardo A. Feb 12 '16 at 18:15

1 Answers1

0

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);
Ricardo A.
  • 586
  • 2
  • 7
  • 32