动态隐藏软键盘


@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 );
}
相关标签

扫一扫

在手机上阅读