简体   繁体   中英

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 (ie have the text editor de-select itself when enter is pressed)?

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" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM