android 键盘的隐藏与显示
這個其實很簡單,但是有時候自己就忘記了,所以在這里記錄一下。
1,鍵盤的隱藏。
private void hintKbTwo() {
?InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);???????????
?if(imm.isActive()&&getCurrentFocus()!=null){
??? if (getCurrentFocus().getWindowToken()!=null) {
??? imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
??? }????????????
?}
}
此代碼首先獲得虛擬鍵盤的管理類,然后設置為隱藏。可以在需要隱藏鍵盤時調用此代碼。
2,鍵盤的顯示
private void hintKbTwo() {
?InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);???????????
?if(imm.isActive()){
? ?imm.toggleSoftInput(0, InputMethodManager.RESULT_SHOWN);?
? }????????????
?}
}
此代碼首先獲得虛擬鍵盤的管理類,然后設置為顯示??梢栽谛枰[藏鍵盤時調用此代碼。
就這么的簡單。
總結
以上是生活随笔為你收集整理的android 键盘的隐藏与显示的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android 密码加密
- 下一篇: android 对话框