| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- package eVVM.apk.helper;
- import android.content.Context;
- import android.view.View;
- import android.view.inputmethod.InputMethodManager;
- /**
- * desc : 软键盘工具类
- */
- public final class KeyboardUtils {
- /**
- * 显示软键盘
- *
- * @param view 依附的View
- */
- public static void showKeyboard(View view) {
- if (view == null) return;
- InputMethodManager imm = (InputMethodManager) view.getContext()
- .getSystemService(Context.INPUT_METHOD_SERVICE);
- if (imm != null) {
- //view.requestFocus();
- imm.showSoftInput(view, 0);
- }
- }
- /**
- * 隐藏软键盘
- *
- * @param view 依附的View
- */
- public static void hideKeyboard(View view) {
- if (view == null) return;
- InputMethodManager imm = (InputMethodManager) view.getContext()
- .getSystemService(Context.INPUT_METHOD_SERVICE);
- if (imm != null) {
- imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
- }
- }
- /**
- * 切换软键盘
- *
- * @param view 依附的View
- */
- public static void toggleSoftInput(View view) {
- if (view == null) return;
- InputMethodManager imm = (InputMethodManager) view.getContext()
- .getSystemService(Context.INPUT_METHOD_SERVICE);
- if (imm != null) {
- imm.toggleSoftInput(0, 0);
- }
- }
- }
|