Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)?

like image 685
CaptainForge Avatar asked Dec 18 '25 01:12

CaptainForge


1 Answers

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" />
like image 186
joao2fast4u Avatar answered Dec 20 '25 16:12

joao2fast4u



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!