android控制软键盘弹出或者隐藏

在程序中加入以下代码时,软键盘会出现:

InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
imm.toggleSoftInput(0, InputMethodManager.RESULT_SHOWN);

如果要让软键盘消失,则为以下代码:

InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);

Leave a Reply

Your email address will not be published. Required fields are marked *