通过反射来使edittext获取焦点时,不弹出键盘

    public void setEditTextShowSoftInputOnFocus(EditText mEt, Activity activity) {
        if (mEt == null || activity == null)

            return;

        activity.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) {

            mEt.setInputType(InputType.TYPE_NULL);

        } else {

            Class cls = EditText.class;

            Method setShowSoftInputOnFocus;

            try {

                setShowSoftInputOnFocus = cls.getMethod(methodName,

                        boolean.class);

                setShowSoftInputOnFocus.setAccessible(true);

                setShowSoftInputOnFocus.invoke(mEt, false);

            } catch (NoSuchMethodException e) {

                mEt.setInputType(InputType.TYPE_NULL);

                e.printStackTrace();

            } catch (IllegalAccessException e) {

                e.printStackTrace();

            } catch (IllegalArgumentException e) {

                e.printStackTrace();

            } catch (InvocationTargetException e) {

                e.printStackTrace();

            }

        }
    }

你可能感兴趣的:(通过反射来使edittext获取焦点时,不弹出键盘)