这个其实很简单,但是有时候自己就忘记了,所以在这里记录一下。
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);
}
}
}
此代码首先获得虚拟键盘的管理类,然后设置为显示。可以在需要隐藏键盘时调用此代码。
就这么的简单。