简体   繁体   English

如何在按下“ enter”时取消选择“ EditText”元素

[英]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. 我正在制作一个android应用程序,我有一个EditText元素,在该字段中,一旦您按Enter键,同一页面上其他位置的文本就会更新,尽管您无法立即看到它,因为键盘在路上。 In short, is there a way to have the keyboard go away (ie have the text editor de-select itself when enter is pressed)? 简而言之,有没有办法使键盘消失(即,在按下Enter键时使文本编辑器取消选择自身)?

You just have to set your EditText as singleLine and enable the IMEAction Done, like this: 您只需要将EditText设置为singleLine并启用IMEAction Done,如下所示:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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