toggle Soft Input - Android android.view.inputmethod

Android examples for android.view.inputmethod:KeyBoard

Description

toggle Soft Input

Demo Code

import android.content.Context;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

public class Main {

  public static void toggleSoftInput(Context context, View view, boolean shouldShow) {
    if (context == null) {
      return;//  w  w w .j  a v  a2 s .  c  o m
    }

    InputMethodManager im = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    if (shouldShow) {
      im.showSoftInput(view, InputMethodManager.SHOW_FORCED);
    } else {
      im.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
  }

}

Related Tutorials