Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Close/hide the Android Soft Keyboard

    • 0
    • 5
    • 2
    • 0
    • 0
    • 0
    • 0
    • 0
    • 199
    Comment on it

    When we perform any action on button click and many times we have seen that the keyboard is open and the further activities are going on. The opened keyboard looks very bad on the screen. So to over come this problem here is the method to close the keyboard if opened.

    You just need to call hideKeyboard method and have to pass the activity context as parameter.

    public static void hideKeyboard(Activity activity) {
            //start with an 'always hidden' command for the activity's window
            activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
            //now tell the IMM to hide the keyboard FROM whatever has focus in the activity
            InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
            View currentFocusedView = activity.getCurrentFocus();
            if (currentFocusedView != null) {
                inputMethodManager.hideSoftInputFromWindow(currentFocusedView.getWindowToken(), 0);
            }
        }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: