Java tutorial
//package com.java2s; //License from project: Apache License import android.app.Activity; import android.content.Context; import android.support.annotation.NonNull; import android.view.View; import android.view.inputmethod.InputMethodManager; public class Main { /** * Hides the soft keyboard. * * @param activity The reference of the activity displaying the keyboard. */ public static void hide(@NonNull final Activity activity) { final InputMethodManager iManager = (InputMethodManager) activity .getSystemService(Context.INPUT_METHOD_SERVICE); final View view = activity.getCurrentFocus(); if (view != null && iManager != null) { iManager.hideSoftInputFromWindow(view.getWindowToken(), 0); } } /** * Hides the soft keyboard. * * @param view The view object's reference from which we'll get the window token. */ public static void hide(@NonNull final View view) { final InputMethodManager iManager = (InputMethodManager) view.getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); if (iManager != null) { iManager.hideSoftInputFromWindow(view.getWindowToken(), 0); } } }