Android Custom EditText未在ICS中显示光标

Android Custom EditText未在ICS中显示光标,第1张

概述我的应用程序中有一个EditText,它只接收我放在屏幕上的按钮的输入. 为了避免出现软键盘,我有一个自定义的EditText类,如下所示: public class CustomEditText extends EditText { public CustomEditText(Context context) { super(context);} 我的应用程序中有一个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 Custom EditText未在ICS中显示光标全部内容,希望文章能够帮你解决Android Custom EditText未在ICS中显示光标所遇到的程序开发问题。

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

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1134947.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存