Can anyone tell me how to disable and enable the Enter key in the soft keyboard?
Asked
Active
Viewed 1.6k times
12
-
What exactly are you trying to accomplish? – Shawn Lauzon Sep 01 '11 at 15:01
-
I would also like to know how to do this. I've noticed in my phonegap application that if I use the enter key after completing entry into a text field that sometimes the screen does not render correctly. If I use the native android back button when done it works perfect every time. – blong824 Jan 25 '12 at 14:45
5 Answers
18
just go to your xml and put this attribute in EditText
android:singleLine="true"
and your enter key will be gone

Adnan Ali
- 792
- 1
- 8
- 21
-
1I don't know if this is what they were asking specifically but it's exactly what I needed! Thanks! – Sloganho Jun 17 '15 at 15:31
-
android:singleLine is deprecated but it is working perfectly for this case. Thanks. – Kyaw Min Thu L Feb 17 '17 at 03:52
9
Attach OnEditorActionListener to your text field and return true from its onEditorAction
method, when actionId
is equal to IME_ACTION_DONE. This will prevent soft keyboard from hiding:
EditText txtEdit = (EditText) findViewById(R.id.txtEdit);
txtEdit.setOnEditorActionListener(new OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
// your additional processing...
return true;
} else {
return false;
}
}
});
Refer this LINK.

Community
- 1
- 1

Shankar Agarwal
- 34,573
- 7
- 66
- 64
3
Try this, together imeOptions = actionDone
<EditText
android:id="@+id/edittext_done"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:imeOptions="actionDone"
android:maxLines="1"/>

missionMan
- 873
- 8
- 21
1
In the EditText's
layout put something like this:
android:digits="abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ,"
You can also enumerate the rest of the symbols that you would like to be able to enter there, but not the enter key.

g00dy
- 6,752
- 2
- 30
- 43
-1
I know this question is quite old but an easy way of disabling the enter key is to set android:maxLines="1" in your EditText.

Sam Shute
- 644
- 1
- 6
- 13
-
downvoted, not working. I have an EditText with maxLines="1" and still shows and handles the enter key. – momo Oct 16 '13 at 06:49