barcodereader
barcodereader

Reputation: 2038

How to Prevent Keyboard appearing for EditText that is not enabled

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

Upvotes: 6

Views: 8878

Answers (6)

Tein van der Lugt
Tein van der Lugt

Reputation: 223

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

editText.setShowSoftInputOnFocus(boolean show);

This is exactly what you need.

Upvotes: 1

Tiago Almeida
Tiago Almeida

Reputation: 14237

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.

Upvotes: 28

WmBurkert
WmBurkert

Reputation: 295

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"

Upvotes: 2

Nathan Schwermann
Nathan Schwermann

Reputation: 31503

in your layout file add the attribute to your EditText

android:editable="false"

Upvotes: 1

Jaydeep Khamar
Jaydeep Khamar

Reputation: 5985

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

Upvotes: 0

Austyn Mahoney
Austyn Mahoney

Reputation: 11408

Try setEditable(false) on your EditText.

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

Upvotes: 1

Related Questions