转载请标明出处 :https://blog.youkuaiyun.com/hj_key/article/details/89735881
当有EditText 时怎么禁用系统软键盘?
网上找了很多内容,但效果不太理想,经过很长时间验证推敲,特总结下以备下次使用。
导入需要包文件 import android.text.InputType; import java.lang.reflect.Method;
在初始化edittext 时调用下面方法: public static 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) { // TODO: handle exception } try { method = cls.getMethod("setSoftInputShownOnFocus",boolean.class); method.setAccessible(true); method.invoke(editText, false); }catch (Exception e) { // TODO: handle exception } } }