Sauda Sadaf
Sauda Sadaf

Reputation: 139

Keyboard not getting dismissed even I'm trying to dismiss Android

I have a editText , and two buttons when I click cancel, i have the disable the edit text and hide keyboard.

     case R.id.verify_cancel:

 hideMobileNoEditOption();
            showAndHideError(verify_layout, false);
            showAndHideError(mobile_error_tv, false);
            mobile_number_et.clearFocus();

this is the code for hideMobileNoEditOption();

mobile_number_et.clearFocus();
        AppUtil.hideSoftKeyboard(this);
        mobile_number_et.setCursorVisible(false);
        mobile_number_et.setFocusable(false);
        mobile_number_et.setEnabled(false);
        mobile_number_et.setTextIsSelectable(false);
        mobile_number_et.setTextColor(ContextCompat.getColor(getBaseContext(), R.color.zero_title));

and this is the code for hideing keyboard.

InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);

        if (null != activity.getCurrentFocus()) {

            inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);

        }

But my key board is not getting dismissed for what reason God knows, can anyone please help? Thanks in advance

Upvotes: 0

Views: 246

Answers (1)

Rakshit Nawani
Rakshit Nawani

Reputation: 2604

Try this, this code is working for me

     /**
     * For Hiding the keyboard
     */

    public void hideKeyboard() {
        View view = this.getCurrentFocus();
        if (view != null) {
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }
    }

Upvotes: 1

Related Questions