版权声明:本文为博主原创文章,转载请标明出处。 https://cloud.tencent.com/developer/article/1331013
Android中隐藏显示键盘操作:
隐藏键盘:
/**
* 隐藏软键盘
*/
public static void hideSoftInputMethod(Activity act) {
View view = act.getWindow().peekDecorView();
if (view != null) {
// 隐藏虚拟键盘
InputMethodManager inputmanger = (InputMethodManager) act
.getSystemService(act.INPUT_METHOD_SERVICE);
inputmanger.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
切换键盘:
/**
* 切换软件盘 显示隐藏
*/
public static void switchSoftInputMethod(Activity act) {
// 方法一(如果输入法在窗口上已经显示,则隐藏,反之则显示)
InputMethodManager iMM = (InputMethodManager) act
.getSystemService(Context.INPUT_METHOD_SERVICE);
iMM.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
}
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有