public class ImmSolftManager {
private Activity activity;
InputMethodManager imm;
public ImmSolftManager(Activity activity){
this.activity = activity;
imm = (InputMethodManager)
activity.getSystemService(Context.INPUT_METHOD_SERVICE);
}
public void showKeyboard(boolean isShow) {
//当前获取到焦点的view
View currentFocus = activity.getCurrentFocus();
if (null == imm)
return;
if (isShow) {
if (currentFocus != null) {
//有焦点打开
imm.showSoftInput(currentFocus, 0);
} else {
//无焦点打开
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}
} else {
if (currentFocus != null) {
//有焦点关闭
imm.hideSoftInputFromWindow(currentFocus.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
} else {
//无焦点关闭
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
}
}
}
}
android打开关闭软键盘
最新推荐文章于 2023-12-30 19:06:51 发布