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);


or

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

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,


editText.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);

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.

Comments

Popular posts from this blog

AlarmManager and Notification in Android

Swipe Action and ViewFlipper in Android

Open Gallery and get the selected image in appplication