PowenKo, Android, Tutorial 090-2, System, software keyboard hide and show part2/2

November 2, 2011   ·   0 Comments

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.

shareShare on FacebookShare on Google+Share on LinkedInEmail this to someonePrint this pageBuffer this pageDigg thisFlattr the authorShare on RedditPin on PinterestShare on StumbleUponShare on TumblrTweet about this on Twitter

By


Readers Comments (0)


You must be logged in to post a comment.

PowenKo’s Online Store

powenko_arduinoBook
Android7

Amazon

adsbygoogle

Recent Posts

Categories

Amazon