1、方法一(如果输入法在窗口上已经显示,则隐藏,反之则显示)
[java] view plaincopy
- InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
- imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
2、方法二(view为接受软键盘输入的视图,SHOW_FORCED表示强制显示)
[java] view plaincopy
- InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
- imm.showSoftInput(view,InputMethodManager.SHOW_FORCED);
[java] view plaincopy
- imm.hideSoftInputFromWindow(view.getWindowToken(), 0); //强制隐藏键盘
时间: 2024-10-07 03:20:09