Android 检测 OnScreen 键盘的完成按键

是否可以检测到什么时候按下了 onScreen 键盘的 Done键?

56670 次浏览

是的,有可能:

editText = (EditText) findViewById(R.id.edit_text);


editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
// do your stuff here
}
return false;
}
});

请注意,您必须导入以下库:

import android.view.KeyEvent;
import android.view.inputmethod.EditorInfo;
import android.widget.TextView;

编辑器信息是最有用的类时,你必须处理任何 在 Android 应用程式中输入的用户类型 login/registration/search operations we can use it for more accurate 编辑器信息类描述了 文本编辑对象,输入方法将直接为 与编辑文本内容通信。

你可以试试 译自: 美国《科学》杂志网站(http://developer.android.com/intl/es/reference/android/view/inputmethod/EditorInfo.html # IME _ ACTION _ DONE)原文地址: http://developer.android.com/intl/es/reference/android/view/inputmethod/EditorInfo.html

这个操作执行一个 Done操作,没有任何输入,IME将被关闭。

使用 setOnEditorActionListener

EditTextObj.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
boolean handled = false;
if (actionId == EditorInfo.IME_ACTION_DONE) {
/* Write your logic here that will be executed when user taps next button */
handled = true;
}
return handled;
}
});

用小刀你就能做到

@OnEditorAction(R.id.signInPasswordText)
boolean onEditorAction(TextView v, int actionId, KeyEvent event){
if (actionId == EditorInfo.IME_ACTION_DONE || event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
/* Write your logic here that will be executed when user taps next button */
}
return false;
}