Android 手動顯示和隱藏軟鍵盤

2021-07-16 21:55:05 字數 1034 閱讀 6958

1、如果輸入法在視窗上已經顯示,則隱藏,反之則顯示

inputmethodmanager imm = (inputmethodmanager) getsystemservice(context.input_method_service);  

imm.togglesoftinput(0, inputmethodmanager.hide_not_always);

2、強制顯示或隱藏鍵盤

inputmethodmanager imm = (inputmethodmanager) getsystemservice(context.input_method_service);  

imm.showsoftinput(view,inputmethodmanager.show_forced); //強制顯示鍵盤

imm.hidesoftinputfromwindow(view.getwindowtoken(), 0); //強制隱藏鍵盤

注意:view為接受軟鍵盤輸入的檢視,show_forced表示強制顯示。

3、呼叫隱藏系統預設的輸入法

((inputmethodmanager)getsystemservice(context.input_method_service)).hidesoftinputfromwindow(widgetsearchactivity.this

.getcurrentfocus().getwindowtoken(), inputmethodmanager.hide_not_always);//(widgetsearchactivity是當前的activity)

4、獲取輸入法開啟的狀態

inputmethodmanager imm = (inputmethodmanager)getsystemservice(context.input_method_service);  

boolean isopen=imm.isactive();//isopen若返回true,則表示輸入法開啟

Android 手動顯示和隱藏軟鍵盤

本人用過第乙個,第二個靠譜 1 方法一 如果輸入法在視窗上已經顯示,則隱藏,反之則顯示 inputmethodmanager imm inputmethodmanager getsystemservice context.input method service imm.togglesoftinpu...

Android 手動顯示和隱藏軟鍵盤

1 方法一 如果輸入法在視窗上已經顯示,則隱藏,反之則顯示 inputmethodmanager imm inputmethodmanager getsystemservice context.input method service imm.togglesoftinput 0 inputmetho...

隱藏和顯示

display none 隱藏物件 隱藏之後不佔據位置。display block 除了轉換為塊元素之外,同時還有顯示元素的意思。visibility hidden 隱藏之後佔據位置 visibility visible 顯示隱藏。只對溢位的隱藏。overflow visible 不剪下內容也不新增...