How to Prevent Keyboard appearing for EditText tha

2019-02-13 14:48发布

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

6条回答
叛逆
2楼-- · 2019-02-13 15:06

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

查看更多
看我几分像从前
3楼-- · 2019-02-13 15:09

Try setEditable(false) on your EditText.

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

查看更多
Bombasti
4楼-- · 2019-02-13 15:09

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

editText.setShowInputOnFocus(boolean show);

This is exactly what you need.

查看更多
我命由我不由天
5楼-- · 2019-02-13 15:10

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"
查看更多
贪生不怕死
6楼-- · 2019-02-13 15:13

in your layout file add the attribute to your EditText

android:editable="false"

查看更多
爱情/是我丢掉的垃圾
7楼-- · 2019-02-13 15:27

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.

查看更多
登录 后发表回答