CaptainForge
CaptainForge

Reputation: 1395

How to have an 'EditText' element deselect itself when 'enter' is pressed

I'm making an android application and I have an EditText element where, once you press enter in that field, text elsewhere on the same page is updated, though you cannot immediately see it because the keyboard is in the way. In short, is there a way to have the keyboard go away (i.e. have the text editor de-select itself when enter is pressed)?

Upvotes: 3

Views: 1530

Answers (1)

joao2fast4u
joao2fast4u

Reputation: 6892

You just have to set your EditText as singleLine and enable the IMEAction Done, like this:

       <EditText
        android:id="@+id/myEditText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ellipsize="end"
        android:gravity="center"
        android:singleLine="true"
        android:imeActionLabel="Done"
        android:imeOptions="actionDone"
        android:textColor="@android:color/black"
        android:textSize="16sp" />

Upvotes: 2

Related Questions