android輸入法狀態控制

在Android程序中控制打開和關閉輸入法



在應用程序中,我們經常需要控制EditText的輸入法打開與關閉,手指touch之後,自動打開了輸入法,可是怎麼控制關閉輸入法,除了輸入法自己的關閉按鈕之外,還有以下的方法。

     一、打開輸入法窗口:

InputMethodManager inputMethodManager = (InputMethodManager)               getSystemService(Context.INPUT_METHOD_SERVICE);

// 接受軟鍵盤輸入的編輯文本或其它視圖

imm.showSoftInput(submitBt,InputMethodManager.SHOW_FORCED);



二、關閉出入法窗口


InputMethodManager inputMethodManager = (InputMethodManager)               getSystemService(Context.INPUT_METHOD_SERVICE);


inputMethodManager.hideSoftInputFromWindow(OpeListActivity.this.getCurrentFocus().getWindowToken(),


InputMethodManager.HIDE_NOT_ALWAYS);


//接受軟鍵盤輸入的編輯文本或其它視圖

inputMethodManager


.showSoftInput(submitBt,InputMethodManager.SHOW_FORCED);

三、如果輸入法打開則關閉,如果沒打開則打開

InputMethodManager m=(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

m.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);

四、獲取輸入法打開的狀態

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
boolean isOpen=imm.isActive();
isOpen若返回true,則表示輸入法打開

轉載:

http://wolfgangkiefer.blog.163.com/blog/static/86265503201181205238909/


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章