Android中關於鍵盤的操做

1、打開輸入法窗口:
InputMethodManager inputMethodManager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
// 接受軟鍵盤輸入的編輯文本或其它視圖
imm.showSoftInput(submitBt,InputMethodManager.SHOW_FORCED);

2、關閉出入法窗口

InputMethodManager inputMethodManager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(OpeListActivity.this.getCurrentFocus().getWindowToken()
,InputMethodManager.HIDE_NOT_ALWAYS);
//接受軟鍵盤輸入的編輯文本或其它視圖
inputMethodManager.showSoftInput(submitBt,InputMethodManager.SHOW_FORCED);

3、若是輸入法打開則關閉,若是沒打開則打開
InputMethodManager m=(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
m.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);

4、獲取輸入法打開的狀態
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
boolean isOpen=imm.isActive();
isOpen若返回true,則表示輸入法打開android


另外在Android中有多個可供輸入的控件的時候,加載以後,第一個可輸入的控件獲取焦點,所以加載完畢,輸入框軟鍵盤彈出,咱們能夠採用獲取焦點觸摸模式能夠解決問題,咱們能夠在最外層的控件容器中添加以下內容web

android:focusable="true"ide

android:fousableInTouchMode="true"this

相關文章
相關標籤/搜索