android:imeOptions="actionDone" does not work

2018, Jan 11    

There might be many other reason to this. But here I am going to share what I faced and how I fixed it.

Problem:

Let’s consider you want to have an EditText for taking only alpha numeric values as input. So here is an Android XML layout which will cause the error mentioned.

<android.support.v7.widget.AppCompatEditText
        android:id="@+id/newDeliverable"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:digits="1234567890 abcdefghijklmnopqrstuvwxyz"
        android:hint="@string/hint_add_new_deliverable"
        android:imeOptions="actionDone"
        android:inputType="text" />

If you observe closely, the EditText has android:digits attribute for filtering the allowed characters for input. This attribute is the cause behind this problem.

Solution:

So to avoid this problem, you have to add android:singleLine attribute. Below is the final working XML.

<android.support.v7.widget.AppCompatEditText
        android:id="@+id/newDeliverable"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:digits="1234567890 abcdefghijklmnopqrstuvwxyz"
        android:hint="@string/hint_add_new_deliverable"
        android:imeOptions="actionDone"
        android:inputType="text"
        android:singleLine="true" />

Conclusion:

If we have android:digits attribute in EditText, then android:imeOptions will work ones we add android:singleLine attribute.