android – How can I get a "done" button in softkeyboard?-ThrowExceptions

Exception or error:

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).

How to solve:

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

###

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"/>

###

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) !

###

Use TextView.setImeOptions and pass it actionDone.

###

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

Leave a Reply

Your email address will not be published. Required fields are marked *