Android examples for Android OS:Keyboard
Hide any keyboard that might be open
//package com.java2s; import android.app.Activity; import android.content.Context; import android.view.View; import android.view.inputmethod.InputMethodManager; public class Main { /**/*from w w w .j a v a2 s . c o m*/ * Hide any keyboard that might be open */ public static void hideKeyboard(Activity activity) { InputMethodManager inputMethodService = (InputMethodManager) activity .getSystemService(Context.INPUT_METHOD_SERVICE); // if (inputMethodService != null && inputMethodService.isActive()) { if (inputMethodService != null) { inputMethodService.hideSoftInputFromWindow(activity.getWindow() .getDecorView().getWindowToken(), 0); } } public static void hideKeyboard(Activity activity, View view) { InputMethodManager inputMethodService = (InputMethodManager) activity .getSystemService(Context.INPUT_METHOD_SERVICE); if (inputMethodService != null && inputMethodService.isActive()) { inputMethodService.hideSoftInputFromWindow( view.getWindowToken(), 0); } } }