Android

关注公众号 jb51net

关闭
首页 > 软件编程 > Android > Android 检测键盘显示

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

投稿:lqh

这篇文章主要介绍了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; 
 } 
}

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

您可能感兴趣的文章:
阅读全文