2

Is there some way to know that virtual keyboard is made hidden by user during run time. Before tagging me duplicate question, first understand my question because it seems like duplicate and I also found lots of question with related topic. But not found any answer.

My problem is during some event to occur like say orientation change, I need to know whether user has minimized the keyboard or not.So that I take action accordingly. I tried to be very specific to question even any explanation feel free to ask. Any help will appreciated .Thanks in advance My Try

final View activityRootView = findViewById(R.id.ll_main_root);
                activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
                    @Override
                    public void onGlobalLayout() {
                        int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight();
                        if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...
                            Toast.makeText(MainActivity.instance, "KeyBoarad" + value, Toast.LENGTH_LONG).show();
                        }
                     }
                });
Android
  • 3,828
  • 9
  • 46
  • 79

2 Answers2

1

Hey It may be late but just for the query and my suggestion. I was facing the same issue somewhat. Actually in my case while orientation change my keyboard was getting minimized even if it was visible before orientation change. So I used android:windowSoftInputMode="stateUnchanged" so that my keyboard remains visible even on orientation change.

And there may be one more issue that u want to change the visiblity may be so u can use toggleSoftInputFromWindow (IBinder windowToken, int showFlags, int hideFlags).

Specifically

InputMethodManager inputMgr = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); inputMgr.toggleSoftInput(0, 0);

Hope it help.

Android
  • 3,828
  • 9
  • 46
  • 79
  • Although post is old and I already left that portion of code but still just say coincidence i needed somewhat what u faced, so I am upvoting u and will try out your code. Thnaks. – Android Jul 23 '12 at 12:00
1

Pretty much duplicate of this one: How to capture the "virtual keyboard show/hide" event in Android?

and this one: Android EditText, soft keyboard show/hide event?

The conclusion seems to be that there is NO way to capture this, some people uses hacks where you capture the size of the screen and use that parameter.

Community
  • 1
  • 1
Warpzit
  • 27,966
  • 19
  • 103
  • 155
  • Problem is there. This hack is not working . There must be some way out :-( – Android Mar 30 '12 at 08:53
  • heh be my guest to waste countless of hours :) have you considered another approach to your problem? You can check if the keyboard is open whenever you make a configuration change and then handle it accordingly. – Warpzit Mar 30 '12 at 09:01
  • haha, I have no option but to give it a shot. Hope some one know how to do that. and this hack is I don't know is not working for me. The screen size and height one – Android Mar 30 '12 at 10:19
  • maybe this helps: http://stackoverflow.com/questions/2150078/android-is-software-keyboard-shown – Warpzit Mar 30 '12 at 11:03
  • From here only I tried in my code , But portion is done. But On using onConfigurationChange() method , layout is getting disturb even if I am getting keyboard state. Can you suggest me demo for implementation of onOrientationchangeEventListner. – Android Mar 30 '12 at 11:22
  • Look here: http://developer.android.com/guide/topics/resources/runtime-changes.html – Warpzit Mar 30 '12 at 11:24