0

I am working on an app where I need to open my own custom soft keyboard for text input.To do that I am disabling the default soft keyboard and enabling the custom one. It works fine on Jelly Bean version. However when I run the same code on Nexus 7 Tab Kitkat version it does not hide the default soft keyboard. I am using the following code for hiding the default soft Keyboard:Any idea it his not working on Kit Kat version on Nexus 7 tab?? I have researched a lot but I have not been able to figure it out.

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

Thanks in advance

Sanjeev Sangral
  • 1,275
  • 2
  • 23
  • 35

2 Answers2

0

You can try the following:

public void hideKeyboard(Activity context, View v) {
    InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    inputMethodManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
Leigh
  • 1,445
  • 2
  • 20
  • 40
  • I have used your code but still I am facing the same issue ...doesnot work on Nexus 7 Tab Kitkat – Sanjeev Sangral Jan 23 '15 at 11:32
  • Hmmm I have used this on a Nexus 7 with Jelly Bean, works just fine. Have you looked over the answers in [this post](http://stackoverflow.com/questions/1109022/close-hide-the-android-soft-keyboard)? – Leigh Jan 23 '15 at 12:30
  • @ Leigh: yeah i know it works just fine with jellt bean but not with kit kat..i need a work around for this.. – Sanjeev Sangral Jan 24 '15 at 05:58
0

Use this method.

public static void hideKeyboard (Context context) {

        try {
            InputMethodManager inputManager = (InputMethodManager) context.getSystemService (Context.INPUT_METHOD_SERVICE);

            View view = ((Activity) context).getCurrentFocus ();
            if (view != null) {
                inputManager.hideSoftInputFromWindow (view.getWindowToken (), InputMethodManager.HIDE_NOT_ALWAYS);
            }
        }
        catch (Exception e) {
            e.printStackTrace ();
        }
    }

P.S. Donot pass any view. this will be done automatically

Murtaza Khursheed Hussain
  • 14,714
  • 7
  • 52
  • 78