Android Custom EditText未在ICS中显示光标

我的应用程序中有一个EditText,它只接收我放在屏幕上的按钮的输入.

为了避免出现软键盘,我有一个自定义的EditText类,如下所示:

public class CustomEditText extends EditText {

    public CustomEditText(Context context) {         
        super(context);
}

    public CustomEditText(Context context,AttributeSet attrs) {
        super(context,attrs);
    }

    @Override
    // disables Keyboard;
    public boolean onCheckIsTextEditor() {
        return false;
    }   

}

这会成功阻止键盘出现,但在ICS中,这种方法也会阻止Cursor出现.

setCursorVisible(true)没有任何效果.

我已经尝试了隐藏软键盘的替代方法,例如使用android:editable =“false”和.setKeyListener(null);但这些解决方案都没有在我的测试中发挥过作用.键盘总是出现.

那么,有没有办法在ICS中返回光标,同时保持onCheckIsTextEditor覆盖原样?

解决方法

你为什么不尝试像这样禁用软键盘

PINLockactivity.java

//text field for input sequrity pin
    txtPin=(EditText) findViewById(R.id.txtpin);
    txtPin.setInputType(
      InputType.TYPE_CLASS_NUMBER | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    txtPin.setSelection(txtPin.getText().length());
    txtPin.setTextSize(22);
    txtPin.setSingleLine(true);


    //disable keypad
    txtPin.setonTouchListener(new OnTouchListener(){
        @Override
        public boolean onTouch(View v,MotionEvent event) {

              int inType = txtPin.getInputType(); // backup the input type
              txtPin.setInputType(InputType.TYPE_NULL); // disable soft input
              txtPin.onTouchEvent(event); // call native handler
              txtPin.setInputType(inType); // restore input type
                return true; // consume touch even
        }
        });

并为此EditText字段

xml代码

<EditText android:layout_width="wrap_content" 
            android:id="@+id/txtpin"  
            android:maxLength="4" 
            android:layout_height="37dp" 
            android:gravity="center_horizontal" 
            android:longClickable="false" 
            android:padding="2dp"

            android:inputType="textPassword|number" 
            android:password="true" 
            android:background="@drawable/edittext_shadow" 
            android:layout_weight="0.98" 
            android:layout_marginLeft="15dp">
                <requestFocus></requestFocus>
   </EditText>

这对我来说可以正常使用光标输入安全PIN.

我从按钮而不是键盘输入输入.

相关文章

这篇“android轻量级无侵入式管理数据库自动升级组件怎么实现...
今天小编给大家分享一下Android实现自定义圆形进度条的常用方...
这篇文章主要讲解了“Android如何解决字符对齐问题”,文中的...
这篇文章主要介绍“Android岛屿数量算法怎么使用”的相关知识...
本篇内容主要讲解“Android如何开发MQTT协议的模型及通信”,...
本文小编为大家详细介绍“Android数据压缩的方法是什么”,内...