在不同的sdk版本下所用到的方法也不一样,所以要先判断sdk的版本是否低于10,如果在10以下可以直接用过editText.setInputType(InputType.TYPE_NULL);来设置不弹出软键盘 在 public void disableShowSoftInput(EditText editText) { 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) { e.printStackTrace(); } try { method = cls.getMethod("setSoftInputShownOnFocus", boolean.class); method.setAccessible(true); method.invoke(editText, false); } catch (Exception e) { e.printStackTrace(); } } }
Android中EditText在点击的时候不弹出系统键盘
最新推荐文章于 2024-05-09 00:53:18 发布