10e1276e7f6b52850606adc1aa6ccb0304bbf52e.svn-base 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package eVVM.apk.helper;
  2. import android.content.Context;
  3. import android.view.View;
  4. import android.view.inputmethod.InputMethodManager;
  5. /**
  6. * desc : 软键盘工具类
  7. */
  8. public final class KeyboardUtils {
  9. /**
  10. * 显示软键盘
  11. *
  12. * @param view 依附的View
  13. */
  14. public static void showKeyboard(View view) {
  15. if (view == null) return;
  16. InputMethodManager imm = (InputMethodManager) view.getContext()
  17. .getSystemService(Context.INPUT_METHOD_SERVICE);
  18. if (imm != null) {
  19. //view.requestFocus();
  20. imm.showSoftInput(view, 0);
  21. }
  22. }
  23. /**
  24. * 隐藏软键盘
  25. *
  26. * @param view 依附的View
  27. */
  28. public static void hideKeyboard(View view) {
  29. if (view == null) return;
  30. InputMethodManager imm = (InputMethodManager) view.getContext()
  31. .getSystemService(Context.INPUT_METHOD_SERVICE);
  32. if (imm != null) {
  33. imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
  34. }
  35. }
  36. /**
  37. * 切换软键盘
  38. *
  39. * @param view 依附的View
  40. */
  41. public static void toggleSoftInput(View view) {
  42. if (view == null) return;
  43. InputMethodManager imm = (InputMethodManager) view.getContext()
  44. .getSystemService(Context.INPUT_METHOD_SERVICE);
  45. if (imm != null) {
  46. imm.toggleSoftInput(0, 0);
  47. }
  48. }
  49. }