Java tutorial
//package com.java2s; import android.content.Context; import android.os.IBinder; import android.view.View; import android.view.inputmethod.InputMethodManager; public class Main { public static void hideSoftInput(Context context, View focusView) { InputMethodManager imm = from(context); if (imm.isActive()) { IBinder token = focusView.getWindowToken(); imm.hideSoftInputFromWindow(token, InputMethodManager.HIDE_NOT_ALWAYS); } } public static InputMethodManager from(Context context) { return (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); } public static boolean isActive(Context context) { InputMethodManager imm = from(context); return imm.isActive(); } public static boolean isActive(Context context, View focusView) { InputMethodManager imm = from(context); return imm.isActive(focusView); } }