Android fragment和activity中隐藏软键盘

对于fragment

在onclick事件中添加:

InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);

imm.hideSoftInputFromWindow(getActivity().getWindow().getDecorView().getWindowToken(), 0);

对于activity

在onclick事件中添加:

InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);

imm.hideSoftInputFromWindow(context.getWindow().getDecorView().getWindowToken(), 0);
原创文章 31 获赞 30 访问量 7091

猜你喜欢

转载自blog.csdn.net/qq_41912398/article/details/105419862