[转]Android EditText不弹出输入法以及光标设置

最近在做拨号应用,需要点击输入框的时候弹出自定义的键盘,隐藏系统的输入法。网上找了不少资料,终于给解决了,通过 android:inputType:指定输入法的类型,int类型,可以用|选择多个。取值可以参考:android.text.InputType类。取值包括:text,textUri, phone,number,等.

Android SDK中有这么一句话“If the given content type is TYPE_NULL then a soft keyboard will not be displayed for this text view”,
先将EditText的InputType改变为TYPE_NULL,输入法就不会弹出.然后再设置监听,再重新设置它的InputType.

 

 

et_input.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                
                LogUtil.e(TAG, "EditText click");
                
                int inType = et_input.getInputType(); // backup the input type  
                et_input.setInputType(InputType.TYPE_NULL); // disable soft input      
                et_input.onTouchEvent(event); // call native handler      
                et_input.setInputType(inType); // restore input type 
                
                // 光标置后
                CharSequence text = et_input.getText();
                if (text instanceof Spannable) {
                    Spannable spanText = (Spannable) text;
                    Selection.setSelection(spanText, text.length());
                }
                
                if(ll_keyboard.getVisibility()==View.GONE){    //弹出拨号键盘
                    ll_options.setVisibility(View.GONE);
                    ll_keyboard.setVisibility(View.VISIBLE);
                }
                return true;   
            }                    
        });

 



源:http://www.xuebuyuan.com/2005929.html
posted @ 2015-04-11 00:51  冰雪一舟  阅读(413)  评论(0编辑  收藏  举报