Java tutorial
//package com.java2s; //License from project: LGPL import android.app.Activity; import android.content.Context; import android.view.View; import android.view.inputmethod.InputMethodManager; public class Main { public static void hideKeyboard(Activity activity) { InputMethodManager m = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); if (m != null) { m.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); } } public static void hideKeyboard(View view) { InputMethodManager imm = (InputMethodManager) view.getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); if (imm != null) { imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } } }