zoukankan      html  css  js  c++  java
  • [转]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
  • 相关阅读:
    Nexus3.0私服搭建
    JavaScript
    Spring基础
    Hibernate注解
    HTML5
    Apache Tomcat
    Java安装(Ubuntu)
    C++ 日期 & 时间
    C++ 引用
    C++ 指针
  • 原文地址:https://www.cnblogs.com/qvbrgw/p/4416073.html
Copyright © 2011-2022 走看看