43

I have a problem using an EditText in Android 2.3.

I have an EditText defined with android:imeOptions="actionDone" property but when I'm writing by the virtual keyboard the return key doesn't detect the actionDone and it introduce a return line.

In Android 2.2 is working right.

<EditText android:layout_height="wrap_content"
    android:layout_width="fill_parent" 
    android:imeOptions="actionDone" />
Octavian Helm
  • 39,405
  • 19
  • 98
  • 102
Alex
  • 6,957
  • 12
  • 42
  • 48
  • It's worth noticing that I've found that implementing a TextWatcher can sometimes have strange effects on the actionDone option. – deepwinter Apr 25 '13 at 23:59

3 Answers3

123

I have resolved this issue. I have added the android:singleLine="true" property and it works right.

<EditText android:layout_height="wrap_content"
    android:layout_width="fill_parent" 
    android:imeOptions="actionDone"
    android:singleLine="true" 
 />
Alex
  • 6,957
  • 12
  • 42
  • 48
  • 4
    Thanks for this. It works for `android:imeOptions="actionNext" android:nextFocusDown="@+id/addjob_description" android:singleLine="true"` as well. – Ants Oct 18 '11 at 03:32
  • 4
    Does anyone know why this is working? I'm not complaining, though :))) – luigi7up Nov 15 '11 at 15:59
  • it is a little strange indeed that you need to add also `android:singleLine="true"` so `android:imeOptions="actionSearch"` have an effect... – Paul Jun 22 '12 at 07:02
  • 2
    I believe it only works when single line is enabled because it uses the same button (at least on my Android). – Pijusn Aug 06 '12 at 16:53
  • 1
    Paul, it is so, because in case of a multi-line text, the default ime action is a carriage return. To change it to something else, there should be a single-line text. – lomza Feb 19 '13 at 08:24
  • 4
    Also note that setting some inputTypes will cause the imeOption to be ignored. For example, setting the inputType to textShortMessage will give you the smiley faces key even if the imeOption is set to something like actionDone. – Ian G. Clifton Mar 18 '13 at 20:50
  • Dang. I want 'Done' on a multi-line text box. Is that not possible? – MrPickles7 Nov 24 '15 at 11:34
  • `android:singleLine="true"` is deprecated. Use `android:maxLines="1" android:inputType="text"` instead for newer versions. – Ankit Popli Apr 20 '16 at 11:50
  • and still in December 2016 this is the only way i can get imeOptions working on `inputType="text"`, given that it was deprecated in v3 and we are now in v25 that just seems insane – Joe Maher Dec 16 '16 at 05:09
9

Another noteworthy point is that the android:imeOptions don't work if you specify android:digits. Not sure if this affects all android versions.

Muhammed Refaat
  • 8,914
  • 14
  • 83
  • 118
cybergen
  • 3,108
  • 1
  • 22
  • 30
  • 4
    Yeah I've noticed that Android decides to overwrite the imeOptions with whatever it decides to put in it... Lol why put it if you're just going to over write it anyways. Another Android annoyance. – Kevin Parker Sep 11 '14 at 05:26
1

Currently in Android Studio 2.2.3 if you use

android:singleLine="true"

IDE gives a warning that it has been deprecated use maxlines instead.

android:maxLines="1"

However maxLines does not solve the problem. The solution is to just add the attribute inputType. Example :

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/actionDoneDemo"
    android:layout_below="@id/nameET"
    android:imeOptions="actionDone"
    android:hint="Action Done Demo"
    android:inputType="text"/>
Akash Chugh
  • 65
  • 2
  • 8