Android Keyboard Hide closeSoftKeyboard(Activity activity)

Here you can find the source of closeSoftKeyboard(Activity activity)

Description

close Soft Keyboard

License

Open Source License

Declaration

public static void closeSoftKeyboard(Activity activity) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import android.app.Activity;
import android.content.Context;
import android.os.IBinder;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

public class Main {
    public static void closeSoftKeyboard(Activity activity) {
        if (activity == null)
            return;
        InputMethodManager inputManager = (InputMethodManager) activity
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        View currentView = activity.getCurrentFocus();
        if (currentView != null) {
            IBinder token = currentView.getWindowToken();
            if (token != null) {
                inputManager.hideSoftInputFromWindow(token,
                        InputMethodManager.HIDE_NOT_ALWAYS);
            }/*from   w  w w . j av  a 2 s.c  o  m*/
        }

    }
}

Related

  1. hideKeyboard(Context context, EditText editText)
  2. hideKeyboard(Context ctx, EditText editText)
  3. hideKeyboard(View view)
  4. hideKeyboard(EditText editText)
  5. hiddenKeyboard(Activity activity)