Android检测到OnScreen键盘的完成按键

时间:2011-02-22 11:21:11

标签: android

是否可以检测到何时按下onScreen键盘的 Done 键?

3 个答案:

答案 0 :(得分:260)

是的,有可能:

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;

答案 1 :(得分:3)

  

当您必须处理任何内容时,编辑器信息是最有用的类   Android应用程序中的用户输入类型。对于例如在   登录/注册/搜索操作我们可以使用它来更准确   键盘输入。编辑器信息类描述了几个属性   直接输入法的文本编辑对象   与编辑文本内容进行通信。

您可以尝试使用 IME_ACTION_DONE

此操作会执行 Done 操作,无需输入任何内容, "git.path": "C:\\Users\\[WINDOWS_USER]\\AppData\\Local\\Programs\\Git\\bin\\git.exe" 将会关闭。

使用 setOnEditorActionListener

IME

答案 2 :(得分:0)

使用牛刀可以做到这一点

@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;
}
相关问题