Skip to content

Instantly share code, notes, and snippets.

@fyhack
Last active February 10, 2017 02:18

Revisions

  1. fyhack renamed this gist Nov 6, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. fyhack created this gist Nov 6, 2013.
    23 changes: 23 additions & 0 deletions gistfile1.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    if (android.os.Build.VERSION.SDK_INT <= 10) { //2.3版本之前使用此方法
    edit.setInputType(InputType.TYPE_NULL);
    } else { //2.3版本以后用反射方法设置setSoftInputShownOnFocus(4.0)的值解决
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    try {
    Class<EditText> cls = EditText.class;
    Method setSoftInputShownOnFocus;
    setSoftInputShownOnFocus = cls.getMethod("setSoftInputShownOnFocus", boolean.class);
    setSoftInputShownOnFocus.setAccessible(true);
    setSoftInputShownOnFocus.invoke(edit, false);
    } catch (Exception e) {
    e.printStackTrace();
    }
    try { // 有部分SDK的方法名字为setShowSoftInputOnFocus(4.2)
    Class<EditText> cls = EditText.class;
    Method setShowSoftInputOnFocus;
    setShowSoftInputOnFocus = cls.getMethod("setShowSoftInputOnFocus", boolean.class);
    setShowSoftInputOnFocus.setAccessible(true);
    setShowSoftInputOnFocus.invoke(edit, false);
    } catch (Exception e) {
    e.printStackTrace();
    }
    }