Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Edittext question, replace keypad enter with done

Tags:

android

xml

I'm defining an edit text like so...

<EditText
android:id="@+id/user"
android:layout_width="200px"
android:layout_height="wrap_content"
android:text="Username"
android:textSize="18sp"
android:gravity="center"
android:layout_x="64px"
android:layout_y="140px"
>

I'd like to replace the "enter" button that appears on the keypad automatically, with a done button that would just close the keypad when the user hits it. I've seen this done on a couple of apps (e.g the Nexus One twitter app) and would like to implement something similar. does anyone know how?

Also is it possible to get the text that appears by default to auto erase when the user click to edit the edittext box? Thanks,

like image 708
Skizit Avatar asked Jun 22 '10 13:06

Skizit


3 Answers

Simple solution: add android:singleLine="true" for the EditText. This will replace the enter with Next (for all edittexts except the last one) and Done (for the last one).

like image 187
cristis Avatar answered Nov 07 '22 22:11

cristis


Just add in the EditText XML : android:imeOptions="actionDone"

like image 38
Sebastien FERRAND Avatar answered Nov 08 '22 00:11

Sebastien FERRAND


Here is an updated answer:

android:maxLines="1"

The accepted answer of android:singleLine="true" has been deprecated.

like image 4
BlackHatSamurai Avatar answered Nov 07 '22 22:11

BlackHatSamurai