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.


Popular posts from this blog

Open Gallery and get the selected image in appplication

Dismiss or Cancel dialog by swipe gesture

AlarmManager and Notification in Android