package com.martin.simpledevelop.utils.keyboard; import android.app.Activity; import android.content.Context; import android.view.inputmethod.InputMethodManager; /** * @Description 软键盘工具类 * @File SaKeyBoardUtils.java * @Package com.martin.simpledevelop.utils.keyboard * @Date 2015年6月26日上午1:22:13 * @Author Donghongyu 1358506549@qq.com * @Version v1.0.0 */ public class SaKeyBoardUtils { /** * 打开键盘. * * @param context * the context */ public static void showSoftInput(Context context) { InputMethodManager inputMethodManager = (InputMethodManager) context .getSystemService(Context.INPUT_METHOD_SERVICE); inputMethodManager.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); } /** * 关闭键盘事件. * * @param context * the context */ public static void closeSoftInput(Context context) { InputMethodManager inputMethodManager = (InputMethodManager) context .getSystemService(Context.INPUT_METHOD_SERVICE); if (inputMethodManager != null && ((Activity) context).getCurrentFocus() != null) { inputMethodManager.hideSoftInputFromWindow(((Activity) context) .getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } } }