簡體   English   中英

即使我嘗試關閉Android,鍵盤也不會關閉

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

我有一個editText,當我單擊“取消”時有兩個按鈕,我禁用了編輯文本並隱藏了鍵盤。

     case R.id.verify_cancel:

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

這是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));

這是隱藏鍵盤的代碼。

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

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

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

        }

但是我的鍵盤並沒有因為上帝知道的原因而被解雇,任何人都可以幫忙嗎? 提前致謝

試試這個,這段代碼對我有用

     /**
     * 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);
        }
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM