大佬教程收集整理的这篇文章主要介绍了Android Custom EditText未在ICS中显示光标,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
为了避免出现软键盘,我有@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出现.
我已经尝试了隐藏软键盘的替代方法,例如使用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,请注明来意。