Java tutorial
//package com.java2s; import android.annotation.TargetApi; import android.app.Activity; import android.content.Context; import android.os.Build; import android.view.View; import android.view.inputmethod.InputMethodManager; import android.widget.EditText; public class Main { @TargetApi(Build.VERSION_CODES.CUPCAKE) public static void hideSoftInput(Activity activity) { View view = activity.getWindow().peekDecorView(); if (view != null) { InputMethodManager inputmanger = (InputMethodManager) activity .getSystemService(Context.INPUT_METHOD_SERVICE); inputmanger.hideSoftInputFromWindow(view.getWindowToken(), 0); } } @TargetApi(Build.VERSION_CODES.CUPCAKE) public static void hideSoftInput(Context context, EditText edit) { edit.clearFocus(); InputMethodManager inputmanger = (InputMethodManager) context .getSystemService(Context.INPUT_METHOD_SERVICE); inputmanger.hideSoftInputFromWindow(edit.getWindowToken(), 0); } }