Android 检测键盘显示或隐藏键盘的实现代码
2019/7/7 20:32:11
本文主要是介绍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; } }
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
这篇关于Android 检测键盘显示或隐藏键盘的实现代码的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-01-18android.permission.read_media_video
- 2024-01-18android_getaddrinfo failed eai_nodata
- 2024-01-18androidmo
- 2024-01-15Android下三种离屏渲染技术
- 2024-01-09Android 蓝牙使用
- 2024-01-06Android对接华为AI - 文本识别
- 2023-11-15代码安全之代码混淆及加固(Android)
- 2023-11-10简述Android语音播报TTS
- 2023-11-06Android WiFi工具类
- 2023-07-22Android开发未来的出路