- 基于窗體打開(kāi)輸入法
/**
* 基于窗體打開(kāi)輸入法
*/
@OnClick(R.id.btn_open_window) public void onOpenWindow(){
InputMethodManager inputMethodManager =
(InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
inputMethodManager.showSoftInput(getWindow().getDecorView(), InputMethodManager.SHOW_FORCED);
}
- 基于窗體打開(kāi)輸入法
/**
* 基于窗體關(guān)閉輸入法
*/
@OnClick(R.id.btn_close_window) public void onCloseWindow(){
InputMethodManager inputMethodManager =
(InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0);
}
- 基于窗體自動(dòng)打開(kāi)關(guān)閉輸入法
/**
* 基于窗體自動(dòng)打開(kāi)關(guān)閉輸入法
*/
@OnClick(R.id.btn_toggle_window) public void onToggleWindow(){
InputMethodManager inputMethodManager =
(InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
inputMethodManager.toggleSoftInputFromWindow(getWindow().getDecorView().getWindowToken(),
0, 0);
}
- 打開(kāi)或關(guān)閉輸入法, 與基于窗體的區(qū)別在于它無(wú)法關(guān)閉基于窗體打開(kāi)的輸入法
/**
* 打開(kāi)或關(guān)閉輸入法, 與基于窗體的區(qū)別在于它無(wú)法關(guān)閉基于窗體打開(kāi)的輸入法
*/
@OnClick(R.id.btn_toggle) public void onToggle(){
InputMethodManager inputMethodManager =
(InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
inputMethodManager.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者