How can I get a "done" button in softkeyboard?
Solution 1
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
Solution 2
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"/>
Solution 3
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) !
Solution 4
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
jul
Updated on July 17, 2020Comments
-
jul almost 4 years
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
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).
-
waqaslam over 12 yearsare you using standard (android) keyboard?
-
jul over 12 yearsI have a Samsung Galaxy 10.1, maybe they have customized softkeyboard?
-
waqaslam over 12 yearsi just tested on my phone with a standard keyboard, and it works fine
-
waqaslam over 12 yearsi dont think you can have
done
andenter
key together, because they both replace each other -
jul over 12 yearsOk, I'm going to ask my new question then. Thanks.
-
CommanderPike about 12 yearsadding the following to the EditText xml, android:singleLine="true"