Android - 处理“输入"在 EditText 中 [英] Android - Handle "Enter" in an EditText

查看:22
本文介绍了Android - 处理“输入"在 EditText 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一种方法可以处理用户在输入 EditText 时按下 Enter,类似于 onSubmit HTML 事件.

I am wondering if there is a way to handle the user pressing Enter while typing in an EditText, something like the onSubmit HTML event.

还想知道是否有一种方法可以操纵虚拟键盘,使完成"按钮被标记为其他内容(例如开始")并在单击时执行特定操作(再次,例如 onSubmit).

Also wondering if there is a way to manipulate the virtual keyboard in such a way that the "Done" button is labeled something else (for example "Go") and performs a certain action when clicked (again, like onSubmit).

推荐答案

我想知道有没有办法处理用户按下 Enter 而输入一个 EditText,比如onSubmit HTML 事件.

I am wondering if there is a way to handle the user pressing Enter while typing in an EditText, something like the onSubmit HTML event.

是的.

也想知道有没有办法操纵虚拟键盘这样完成"按钮是标记其他东西(例如"Go") 并执行某个动作单击时(再次,如 onSubmit).

Also wondering if there is a way to manipulate the virtual keyboard in such a way that the "Done" button is labeled something else (for example "Go") and performs a certain action when clicked (again, like onSubmit).

也是.

您需要查看 android:imeActionIdandroid:imeOptions 属性,加上 setOnEditorActionListener() 方法,全部在 TextView 上.

要将完成"按钮的文本更改为自定义字符串,请使用:

For changing the text of the "Done" button to a custom string, use:

mEditText.setImeActionLabel("Custom text", KeyEvent.KEYCODE_ENTER);

这篇关于Android - 处理“输入"在 EditText 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆