Android隱藏IME鍵盤(hideSoftInputFromInputMethod沒有效果)

來源:互聯網
上載者:User

標籤:pre   無效   沒有   推斷   focus   his   強制   manage   str   

在個別時候,須要強制隱藏AndroidIME鍵盤,如當前鍵盤正在顯示,這個時候點擊了側滑面板。就要強制隱藏IME鍵盤。

網上常見的方法有:

1、InputMethodManager imm = (InputMethodManager) getActivity()
.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);

這個是讓IME狀態發生逆轉,假設當前未顯示則顯示出來。

假設顯示出來,則隱藏。因此是不符合本文所說的應用情境的。

2、imm.hideSoftInputFromInputMethod(passwdEdit.getWindowToken(), 0);

這個經本人在android4.2機子上測試無效。

3、imm.hideSoftInputFromInputMethod(getActivity().getCurrentFocus().getWindowToken(), 0);

經本人測試,依舊無效。大爺的。為了這個小功能浪費了雜家兩個小時時間。

4、imm.hideSoftInputFromWindow(passwdEdit.getWindowToken(), 0);

經過測試,這是唯一有效方法。

另外,有人說:

InputMethodManager imm = (InputMethodManager) this
.getSystemService(Context.INPUT_METHOD_SERVICE);
boolean isOpen=imm.isActive();
Log.i(TAG, "imm.isActive() = " + isOpen);

用以上代碼來推斷當前IME鍵盤是否彈出可見。全然扯淡。isOpen一直為true。

特此記錄。


Android隱藏IME鍵盤(hideSoftInputFromInputMethod沒有效果)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.