【android】禁止Edittext弹出软键盘并且使光标正常显示

来源:互联网 发布:国产芯片 知乎 编辑:程序博客网 时间:2024/05/16 23:47


/** * 禁止Edittext弹出软件盘,光标依然正常显示。 */public void disableShowSoftInput(){if (android.os.Build.VERSION.SDK_INT <= 10) {editText.setInputType(InputType.TYPE_NULL);          } else {                  Class<EditText> cls = EditText.class;                  Method method;            try {                 method = cls.getMethod("setShowSoftInputOnFocus",boolean.class);                  method.setAccessible(true);                  method.invoke(editText, false);              }catch (Exception e) {// TODO: handle exception}                        try {                 method = cls.getMethod("setSoftInputShownOnFocus",boolean.class);                  method.setAccessible(true);                  method.invoke(editText, false);              }catch (Exception e) {// TODO: handle exception}        } }


2 0
原创粉丝点击