0
点赞
收藏
分享

微信扫一扫

VUE-组件间通信(一)props

系统键盘 包含普通键盘和现在很多ROM定制的密码安全键盘

调用已下方法即可解决:
https://developer.android.google.cn/reference/android/widget/TextView#setShowSoftInputOnFocus(boolean)

但是,此方法是API 21Android 5.0加入的, 所以为了兼容低版本, 建议使用已下方法:

 public static final boolean notShowSoftInput(EditText editText) {
      boolean flag = false;

      InputMethodManager imm = (InputMethodManager) editText.getContext()
              .getSystemService(Context.INPUT_METHOD_SERVICE);
      boolean isOpen = imm.isActive();// isOpen若返回true,则表示输入法打开
      if (isOpen) {
          if (imm.hideSoftInputFromWindow(editText.getWindowToken(), 0))
              flag = true;
      }

//        act.getWindow().setSoftInputMode(
//                WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
      int currentVersion = android.os.Build.VERSION.SDK_INT;
      String methodName = null;
      if (currentVersion >= 16) {
          // 4.2
          methodName = "setShowSoftInputOnFocus";
      } else if (currentVersion >= 14) {
          // 4.0
          methodName = "setSoftInputShownOnFocus";
      }

      if (methodName == null) {
          editText.setInputType(InputType.TYPE_NULL);
      } else {
          Class<EditText> cls = EditText.class;
          Method setShowSoftInputOnFocus;
          try {
              setShowSoftInputOnFocus = cls.getMethod(methodName,
                      boolean.class);
              setShowSoftInputOnFocus.setAccessible(true);
              setShowSoftInputOnFocus.invoke(editText, false);
          } catch (NoSuchMethodException e) {
              editText.setInputType(InputType.TYPE_NULL);
              e.printStackTrace();
          } catch (IllegalAccessException e) {
              e.printStackTrace();
          } catch (IllegalArgumentException e) {
              e.printStackTrace();
          } catch (InvocationTargetException e) {
              e.printStackTrace();
          }
      }
      return flag;
  }

4.2低版本中有一个setSoftInputShownOnFocus方法, 但是被声明成hide了, 所以通过反射调用.
再低一点的版本,直接通过setInputType的方式兼容.

以上方法调用后, EditText获取到焦点时,就不会弹出系统的键盘了.
然后弹出自定义的键盘,就可以完美解决冲突了.

翻译

搜索

复制

举报

相关推荐

0 条评论