How to Prevent Keyboard appearing for EditText that is not enabled

假如想象 提交于 2019-11-30 05:17:18

问题


My activity has an EditText which is supposedly not editable until user clicks on edit button for the screen.

I did edit.setEnabled(false) but still a keyboard appears for the user and values can be added to the EditText in the screen via the keyboard even though the screen might look a bit greyed out. What else do I have to do to prevent editing of the EditText until user has specifically pushed an edit button.

Thanks, Steve


回答1:


Attention that setEditable is depecrated.

You can use :

setInputType(EditorInfo.TYPE_CLASS_TEXT)

To turn keyboard on.

setInputType(EditorInfo.TYPE_NULL)

To turn keyboard off.




回答2:


Try setEditable(false) on your EditText.

Set it back to true when you want someone to be able to type in it.




回答3:


in your layout file add the attribute to your EditText

android:editable="false"




回答4:


To make EditText Write Only and not have the keyboard show up I use these two commends within the .xml layout file.

        android:editable="false"
        android:inputType="none"



回答5:


Use edittext.setInputType(0); in your java file.




回答6:


In API level 21, a function has been added to EditText, namely

editText.setShowInputOnFocus(boolean show);

This is exactly what you need.



来源:https://stackoverflow.com/questions/6066095/how-to-prevent-keyboard-appearing-for-edittext-that-is-not-enabled

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!