How to show,hide and close soft keyboard in Android

Android Soft Keyboard Show,Hide, and Close

Method to Show Soft Keyboard 
public static void showSoftKeyboard(View view,Context context) {
     if (view.requestFocus()) {
       InputMethodManager imm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
       imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
    }
}

Method to Hiding Soft Keyboard
public static void hideSoftKeyboard(View view,Context context) {
    if (view.requestFocus()) {
      InputMethodManager imm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
      imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
}

Method to Close Soft Keyboard
public static void closeKeyboard(Context c, IBinder windowToken) {
   InputMethodManager mgr = (InputMethodManager) c.getSystemService(Context.INPUT_METHOD_SERVICE);
   mgr.hideSoftInputFromWindow(windowToken, 0);
}

Comments

Popular posts from this blog

Android studio short cuts lists

Android status bar and navigation bar height