Android开发

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; 
 } 
}

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

这篇关于Android 检测键盘显示或隐藏键盘的实现代码的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!