Android的自定义EditText上没有显示在ICS光标

Android的自定义EditText上没有显示在ICS光标

本文介绍了Android的自定义EditText上没有显示在ICS光标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个EditText在我的应用程序,它是唯一的按钮,我已经放置在屏幕上接收输入。

I have an EditText in my application which is to only receive inputs from buttons I have placed on the screen.

要避免软键盘显示我有一个自定义的EditText类,如下所示:

To avoid the soft keyboard appearing I have a customised EditText class as follows:

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这种方式也出现停止光标。

This successfully stops the keyboard from appearing, however in ICS this approach also stops the Cursor from appearing.

setCursorVisible(真)不产生任何影响。

我试着保持软键盘隐藏的替代方法,如使用机器人:编辑=假 .setKeyListener(空); ,但这些解决方案都曾经工作过的我的测试。总是出现键盘。

I've tried alternate methods of keeping the soft keyboard hidden, such as using android:editable="false" and .setKeyListener(null); but none of these solutions have ever worked in my tests. The keyboard always appears.

那么,有没有办法返回光标在ICS,同时保持onCheckIsTextEditor覆盖,因为它是?

So, is there a way to return the cursor in ICS, while keeping the onCheckIsTextEditor override as it is?

推荐答案

你为什么不尝试禁用按键垫像这样

why don't you try to disable soft key-pad like this

    //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


and for this EditText Field

<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>


这是工作的罚款与我输入安全密码光标。


this is working fine with me for input security PIN with cursor.

我是从按钮没有键盘输入取

i am taking input from button not keypad.

这篇关于Android的自定义EditText上没有显示在ICS光标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 05:10