Android · 2016年8月3日 0

隐藏弹出键盘,Edittext有光标实现方式

1、第一种方式

edittext.setRawInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);
edittext.setTextIsSelectable(true);

2、第二种方式

 /**
     * 禁止Edittext弹出软件盘,光标依然正常显示。
     */
    public void disableShowSoftInput(EditText editText)
    {
        if (android.os.Build.VERSION.SDK_INT <= 10)
        {
//            editText.setInputType(InputType.TYPE_NULL);
            editText.setRawInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);
            editText.setTextIsSelectable(true);
        }
        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
            }
        }
    }

Share this: