Sfoglia il codice sorgente

[공통][New] SoftKeyboardUtil 추가

hyodong.min 7 anni fa
parent
commit
16b9b89b6f

+ 78 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/util/SoftKeyboardUtil.java

@@ -0,0 +1,78 @@
+/*
+ * COPYRIGHT (c) 2018 All rights reserved by HANWHA LIFE.
+ */
+package kr.co.zumo.app.lifeplus.util;
+
+import android.app.Activity;
+import android.content.Context;
+import android.os.IBinder;
+import android.view.View;
+import android.view.inputmethod.InputMethodManager;
+
+/**
+ * SoftKeyboardUtil
+ * <pre>
+ * </pre>
+ *
+ * @author 민효동
+ * @version 1.0
+ * @history 민효동   [2018. 10. 30.]   [최초 작성]
+ * @since 2018. 10. 30.
+ */
+public class SoftKeyboardUtil {
+
+  /**
+   * 키보드 숨기기
+   *
+   * @param activity
+   */
+  public static void hideKeyboard(Activity activity) {
+    //Find the currently focused view, so we can grab the correct window token from it.
+    View view = activity.getCurrentFocus();
+    //If no view currently has focus, create a new one, just so we can grab a window token from it
+    if (view == null) {
+      view = new View(activity);
+    }
+    InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
+    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
+  }
+
+  /**
+   * 키보드 숨기기
+   *
+   * @param context
+   * @param token
+   */
+  public static void hideKeyboard(Context context, IBinder token) {
+    InputMethodManager imm = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE);
+    imm.hideSoftInputFromWindow(token, 0);
+  }
+
+  /**
+   * 키보드 보이기
+   *
+   * @param activity
+   */
+  public static void showKeyboard(Activity activity) {
+    //Find the currently focused view, so we can grab the correct window token from it.
+    View view = activity.getCurrentFocus();
+    //If no view currently has focus, create a new one, just so we can grab a window token from it
+    if (view == null) {
+      view = new View(activity);
+    }
+    InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
+    imm.showSoftInput(view, 0);
+  }
+
+  /**
+   * 키보드 숨기기
+   *
+   * @param context
+   * @param token
+   */
+  public static void showKeyboard(Context context, IBinder token) {
+    InputMethodManager imm = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE);
+    imm.showSoftInputFromInputMethod(token, 0);
+  }
+
+}