Android 检测键盘显示或隐藏键盘的实现代码
程序员文章站
2022-08-08 11:18:34
android 检测键盘是否显示及隐藏键盘的方法~~
android 中对于键盘...
android 检测键盘是否显示及隐藏键盘的方法~~
android 中对于键盘的隐藏与显示的文章很多,今天公司项目需求不仅需要键盘隐藏和显示还需要对键盘的状态进行检查,这里做一个简单的实现实例,供大家参考:
实现代码:
package com.newland.util; import android.app.activity; import android.view.view; import android.view.inputmethod.inputmethodmanager; /** * 系统输入法键盘 检测工具 * * @author yuyh * */ public class imeutil { /** * 隐藏键盘 * @param context */ public static void hideime(activity context) { if (context == null) return; final view v = context.getwindow().peekdecorview(); if (v != null && v.getwindowtoken() != null) { inputmethodmanager imm = (inputmethodmanager) context.getsystemservice(activity.input_method_service); imm.hidesoftinputfromwindow(v.getwindowtoken(), 0); } } /** * 检查系统键盘是否显示 * @param context * @return */ public static boolean issyskeyboardvisiable(activity context) { final view v = context.getwindow().peekdecorview(); if (v != null && v.getwindowtoken() != null) { return true; } return false; } }
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!