21

how can I have a "done" button in my softkeyboard (Samsung Galaxy 10.1, Android 3.1) when writing in an EditText?

Using

 <EditText
     android:id="@+id/comment"
     android:layout_width="772dp"
     android:layout_height="200dp"/>

I get

enter image description here

If possible, I'd also like to remove this "attachment" button.

Anybody can help?

EDIT

I managed to get a "Done" button using

android:inputType="textImeMultiLine",

but the "return" button disappeared...

How can I have both? (I asked this new question here).

Community
  • 1
  • 1
jul
  • 36,404
  • 64
  • 191
  • 318
  • 1
    I think your screen is in portrait mode, so you are not able to see Done button, rotate screen to landscape mode it will visible on right side of EditText. – Yugandhar Babu Jan 26 '12 at 09:38
  • Yes my screen is in portrait mode. Is there any way to have both return and done button in portrait? – jul Jan 26 '12 at 09:40

5 Answers5

63

add this to your EditText xml:

android:imeOptions="actionDone"

or, to set it from code:

yourEditText.setImeOptions(EditorInfo.IME_ACTION_DONE);

for more, read this

waqaslam
  • 67,549
  • 16
  • 165
  • 178
5

Using my Galaxy S2 phone

For the code below, each EditText will have a Return button that adds a new line:

EditText editText = new EditText(this);

For the code below, each EditText will have a Next button that navigates to the next field and the last one will have Done button that will dismiss the keyboard:

EditText editText = new EditText(this);
editText.setInputType(InputType.TYPE_CLASS_TEXT);

For the code below, no change, each EditText has a Return button:

EditText editText = new EditText(this);
editText.setImeOptions(EditorInfo.IME_ACTION_DONE);

For the code below, all EditText will have a Done button and all will dismiss the keyboard.

    EditText editText = new EditText(this);
    editText.setInputType(InputType.TYPE_CLASS_TEXT);
    editText.setImeOptions(EditorInfo.IME_ACTION_DONE);

For layouts use code below:

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:inputType="text"
    android:imeOptions="actionDone"/>
Gary Davies
  • 920
  • 15
  • 12
2

In my Intel x86 Emulator at least, the "Done" key appears only if you specify the input type: "phone", "number", "text", "textPassword", ... with android:inputType. If you don't specify any or you set "textMultiLine", "Done" does not appear.

android:imeOptions="actionDone"

and

editText.setImeOptions(EditorInfo.IME_ACTION_DONE);

seem useless, since they don't change anything either in the first case (where "Done" appears anyway) or in the in the second case (since "Done" keeps not appearing) !

Apostolos
  • 3,115
  • 25
  • 28
1

Add the next code to your EditText in xml

android:imeOptions="actionDone"
android:imeActionLabel="@string/done"
android:singleLine="true"

The android:inputType="text" field is optional

0

Use TextView.setImeOptions and pass it actionDone.

Parag Chauhan
  • 35,760
  • 13
  • 86
  • 95