Android 控制軟鍵盤,親測最好用!


imm = (InputMethodManager) 
context.getSystemService(Context.INPUT_METHOD_SERVICE);

   /**
     * 判斷軟鍵盤 彈出
     */
    public void showSoftInput() {
        if (inputMethodManager.isActive()) {
            inputMethodManager.toggleSoftInput(0, InputMethodManager.RESULT_SHOWN);
        }
    }

    /**
     * 關(guān)閉軟鍵盤 *針對于 有一個(gè)EdtxtView * @param input_email
     */
    public void hideSoftInput(EditText input_email) {
        if (inputMethodManager.isActive()) {
            // 關(guān)閉軟鍵盤,開啟方法相同,這個(gè)方法是切換開啟與關(guān)閉狀態(tài)的
            inputMethodManager.hideSoftInputFromWindow(input_email.getWindowToken(), 0);
        }
     }

      /**
      * 切換軟鍵盤的顯示與隱藏
      */
      public void totleShowSoftInput() {
            imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
      }

        /**
         * 針對于 有多個(gè)EdtxtView * 關(guān)閉所有的軟鍵盤
         */
        public void hideALlSoftInput() {
            View view = ((Activity) context).getWindow().peekDecorView();
            if (view != null) {
                imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
            }
        }
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容