I have been working on the soft keyboard used in our apps. The general idea is this -- create an EditText over a certain area of the screen, then requestFocus() on it. In the onFocusChange() callback the actual call to showSoftInput() is made. The keyboard appearance is standardized by subclassing EditText, with the only goal -- to override onCreateInputConnection() and set .imeOptions = EditorInfo.IME_FLAG_NO_EXTRACT_UI.
This works decent in 3.0+ (some hickups related to onStop/onStart cycles, but otherwise ok), however in 2.3 this approach displays absolutely bizarre behavior. The first time the EditText is created, I get no keyboard (I do get focus to the EditText however, and can back out with the back button). The EditText region does not react to touches either (the first time around). *However*, if this routine is repeated -- a new EditText with identical parameters, everything works as expected! I have tried every possible combination of various forms of showSoftInput, toggleSoftInput, tried clearing focus before requesting it, tried doing all these things with delays introduced, tried setting WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE flags, so on and so forth -- basically every approach I could google. I am happy to say, that I finally arrived at a solution, but why it works as it does is beyond me. *I was hoping that some of you could shed some light on this.* My other goal is to get this 'fix' into the wild, as I am sure others can benefit from it, based on the amount of unanswered questions re: showing soft keyboard on stackoverflow and elsewhere. The secret sauce is in the onFocusChange callback, so I will only list this part of the code in the interest of brevity. Upon examining the code fragment below, you will notice that simply showing-then-hiding the keyboard gets rid of the bizarre behavior, and does not seem to affect functionality otherwise (as far as I can tell). Note that doing only the show or only the hide does not have the desired effect (ie, problem remains). Only doing the pair back-to-back restores desired functionality. My wild guess is that it may have something to do with the window's focus (as opposed to the EditText's). Any thoughts on this matter are welcome. ---------------------------------------------------------------------------- @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { // -- THIS IS THE SECRET mInpMgr.showSoftInput(mKeyboardTriggerView, InputMethodManager.SHOW_FORCED); mInpMgr.hideSoftInputFromWindow(mKeyboardTriggerView.getWindowToken(), 0); // -- need to delay, otherwise doesn't show up when doing start/stop cycles mKeyboardTriggerView.postDelayed(new Runnable() { @Override public void run() { mInpMgr.showSoftInput(mKeyboardTriggerView, InputMethodManager.SHOW_FORCED); } },150); } else { mInpMgr.hideSoftInputFromWindow(mKeyboardTriggerView.getWindowToken(), 0); } } ------------------------------------------------------------------------- -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en