Friday 19 August 2016

Easiest way to hide keyboard in fragment or Activity


Soluton : 1


    //hide keyboard
    public static void hideKeyboard(Context ctx) {
        InputMethodManager inputManager = (InputMethodManager) ctx
                .getSystemService(Context.INPUT_METHOD_SERVICE);

        // check if no view has focus:
        View v = ((Activity) ctx).getCurrentFocus();
        if (v == null)
            return;

        inputManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
    }



Solution : 2


        InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
   





Solution : 3 for Table layout (TAB selected based hid the keyboard)

http://stackoverflow.com/questions/10297376/how-do-i-hide-the-soft-keyboard-when-changing-tabs








No comments:

Post a Comment