源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Android 检测键盘显示或隐藏键盘的实现代码

  • 时间:2020-05-20 05:57 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Android 检测键盘显示或隐藏键盘的实现代码
[b]Android 检测键盘是否显示及隐藏键盘的方法~~[/b]         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; 
 } 
}
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部