欢迎使用CSDN-markdown编辑器

来源:互联网 发布:iphone 办公软件 编辑:程序博客网 时间:2024/06/05 19:25

Activity中的编辑框会默认获得焦点,而弹出软键盘,如果不想让显示Activity时,自动弹出软键盘,有如下两个方式

方式1:

android:windowSoftInputMode=”stateHidden|adjustResize”

方式2:将EditText的焦点转移到其他控件,比如TextView

android:focusable=”true”
android:focusableInTouchMode=”true”

方式3:终极方法,禁止弹出使用自定义键盘光标可用

public void disableShowSoftInput() {        //版本小于4.0直接设置为null        if (android.os.Build.VERSION.SDK_INT <= 10) {            mTxtInput.setInputType(InputType.TYPE_NULL);        } else {            //4.0以上要这么搞            getActivity().getWindow().setSoftInputMode(                    WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);            try {                Class<EditText> cls = EditText.class;                Method setShowSoftInputOnFocus;                setShowSoftInputOnFocus = cls.getMethod("setShowSoftInputOnFocus",                        boolean.class);                setShowSoftInputOnFocus.setAccessible(true);                setShowSoftInputOnFocus.invoke(mTxtInput, false);            } catch (Exception e) {                e.printStackTrace();            }        }    }
0 0
原创粉丝点击