Soft KeyBoard in Android

If in a screen, we have more than one view or we have a tab activity, then we may need to hide the virtual keyboard, if it is open. We can do this using

InputMethodManager imm = context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(this.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);

Always hide soft key board

To always hide the soft keyboprad, use one of the two methods.

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);



Soft Keyboard in Landscape mode

In landscape mode soft keyboard will show in full screen. So edittext of password type won’t work. For this, just add this API,


This will resize the soft keyboard and will show the edit text.

To get the events of soft keyboard, we can use

editText.addTextChangedListener(new TextWatcher());

TextWatcher interface contains three functions as,

- afterTextChanged();
- beforeTextChanged();
- onTextChanged();

which will be called accordingly.

By admin-powenko

Dr. Powen Ko is a teacher and CEO on LoopTek LLC, and like to teaching. if you need to class, please let PowenKo know, he will love to service and sharing. LoopTek web site is

Leave a Reply