Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Android Custom EditText未在ICS中显示光标大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我的应用程序中有@L_772_0@EditText,它只接收我放在屏幕上的按钮的输入.

为了避免出现软键盘,我有@L_772_0@自定义的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 Custom EditText未在ICS中显示光标全部内容,希望文章能够帮你解决Android Custom EditText未在ICS中显示光标所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。